i want to get current windows user full name not with domain name. am using below code to get user name but its giving name with domainname.
string UserName = Request.ServerVariables["AUTH_USER"];
string a=System.Web.HttpContext.Current.User.Identity.Name; string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
in above 3 statements am getting like APAC\san123. but here i want my fullname. here am using mvc with c#.
CodePudding user response:
You can get the users full name from the active directory (using System.DirectoryServices.AccountManagement):
PrincipalContext context = new PrincipalContext(ContextType.Domain,Environment.UserDomainName);
string loginName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
UserPrincipal user = UserPrincipal.FindByIdentity(context, loginName);
string userName = user.Name; //=user.GivenName " " user.Surname;
