- Add Reference to „System.Directory.AccountManagement“
- Set „Copy Local“ to True
- Add following XML Snippet to „Web.Config“
<system.web>
<compilation debug=“true“ targetFramework=“4.5.2″ >
<assemblies>
<add assembly=“System.DirectoryServices, Version=4.0.0.0,Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A“ />
</assemblies>
</compilation> - Add Folder „App_Code“ to your Project
- Add a new Item „Helper – cshtml“ inside this Folder
@using System.DirectoryServices.AccountManagement @helper UserFullName() { using (var context = new PrincipalContext(ContextType.Domain)) { var principal = UserPrincipal.FindByIdentity(context, User.Identity.Name); if (principal != null) { var fullName = string.Format("{0} {1}", principal.GivenName, principal.Surname); @fullName } } }
- Change „Views/Shared/_Layout.cshtml“
From
Hello, @User.Identity.Name!
To
Hello, @UserNameHelper.UserFullName()!