asp.net - 从 ASP.Net BLL 类中的 Windows 身份验证获取全名

标签 asp.net authentication

尝试找出如何从我的 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/

相关文章:

javascript - 为什么页面在javascript:window.open之后使用 “[Object]”空白?

c# - ASP.NET:创建同一网站的多个版本

facebook - 应如何在服务器端使用 Facebook 用户访问 token ?

authentication - 在与 IIS 的 SSL/TLS 通信中,证书请求不包含我的客户端证书

ruby-on-rails - 如何从 access_token 反向查找用户(Rails,Devise)

php - SOAP 身份验证问题

asp.net - 发生错误 - System.InvalidOperationException : Validation of Anti-XSRF token failed

c# - 墨西哥 D.F.以墨西哥 D.F. 的身份出现回发时

asp.net - 如何在 Visual Studio 2008 中运行 Ant?

java - 胖客户端 session 管理和安全