ASP.NET:如何获取Windows系统的用户名

时间:2013-07-04 05:49:24

标签: asp.net .net active-directory ldap windows-authentication

我想构建一个网站,其中用户将传递用户名和密码,并且应根据使用LDAP身份验证托管网站的Windows帐户的用户名和密码来检查这些凭据。怎么可能?是否有必要为此检查提供域名? 谢谢。

2 个答案:

答案 0 :(得分:1)

您可以通过Active Directory身份验证

执行此操作
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domain, userName, password))
        {
            userInfo.IsAuthenticated = pc.ValidateCredentials(userName, password);
            if (userInfo.IsAuthenticated)
            {
                string lastName = userPrincipal.Surname;                
                string givenName = userPrincipal.GivenName;                                 
            }
        }

答案 1 :(得分:0)

如果你想在asp.net中实现windows身份验证,请阅读下面链接的文章,深入了解你需要做的配置。

http://www.codeproject.com/Articles/94612/Windows-Authentication