从ASP.Net BLL类中的Windows身份验证获取全名
试图找出如何从ASP.Net应用程序中的BLL类中获取当前用户在Active Directory中输入的全名。到目前为止,我已经:从ASP.Net BLL类中的Windows身份验证获取全名,asp.net,authentication,Asp.net,Authentication,试图找出如何从ASP.Net应用程序中的BLL类中获取当前用户在Active Directory中输入的全名。到目前为止,我已经: public static string Username { get { var name = System.Security.Principal.WindowsIdentity.GetCurrent().Name; if (name.Contains("\\"))
public static string Username
{
get
{
var name = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
if (name.Contains("\\"))
{
var start = name.IndexOf("\\");
if (name.Length > start)
{
name = name.Substring(start + 1);
}
}
return name;
}
}
问题是,这将返回用户名,但我也需要全名。有人知道这是否可行吗?使用
不。。。但我不想真的质疑广告!
var search = new DirectorySearcher( new DirectoryEntry("LDAP://YourDomain") );
search.Filter = "(sAMAccountName=UserNameHere)"; // put the identity name here
var res = search.FindOne();
var name = res["displayName"]; // I believe this is the right property