asp.net mvc 3 - How do I get the full name of a user in .net MVC 3 intranet app? -
asp.net mvc 3 - How do I get the full name of a user in .net MVC 3 intranet app? -
i have mvc 3 intranet application performs windows authentication against particular domain. render current user's name.
in view,
@user.identity.name
is set domain\username
, want total firstname lastname
you can this:
class="lang-cs prettyprint-override">using (var context = new principalcontext(contexttype.domain)) { var principal = userprincipal.findbyidentity(context, user.identity.name); var firstname = principal.givenname; var lastname = principal.surname; }
you'll need add together reference system.directoryservices.accountmanagement
assembly.
you can add together razor helper so:
class="lang-cs prettyprint-override">@helper accountname() { using (var context = new principalcontext(contexttype.domain)) { var principal = userprincipal.findbyidentity(context, user.identity.name); @principal.givenname @principal.surname } }
if indend on doing view, rather controller, need add together assembly reference web.config well:
<add assembly="system.directoryservices.accountmanagement" />
add under configuration/system.web/assemblies
.
asp.net-mvc-3
Comments
Post a Comment