![get windows auth code get windows auth code](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
public static WindowsIdentityInfo GetWindowsIdentityInfo(HttpContext context)
{
WindowsIdentityInfo info = new WindowsIdentityInfo();
info.IsAuthenticated = false;
if (context==null)
{
WindowsPrincipal winPrincipal = (WindowsPrincipal)context.User;
if (winPrincipal != null)
{
info.IsAuthenticated = winPrincipal.Identity.IsAuthenticated;
info.UserName = winPrincipal.Identity.Name;
if (!string.IsNullOrEmpty(info.UserName))
{
string[] arr = info.UserName.Split('\\');
if (arr != null && arr.Length >= 2)
{
info.DisplayName = GetUserFullName(arr[0], arr[1]);
}
}
info.AuthenticationType = winPrincipal.Identity.AuthenticationType;
}
}
return info;
} private static string GetUserFullName(string domain, string userName)
{
DirectoryEntry userEntry = new DirectoryEntry("WinNT://" + domain + "/" + userName + ",User");
return (string)userEntry.Properties["fullname"].Value;
}