尝试找出如何从我的 ASP.Net 应用程序中的 BLL 类获取在 Active Directory 中输入的当前用户的全名。到目前为止我已经:
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;
}
}
问题是这将返回用户名,但我也需要全名。有人知道这是否可能吗?
最佳答案
使用 DirectorySearcher ...
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
关于asp.net - 从 ASP.Net BLL 类中的 Windows 身份验证获取全名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1215552/