繁体   English   中英

在ASP.NET 3.5应用程序中使用Active Directory / LDAP登录用户

[英]Using Active Directory/LDAP to Login user in ASP.NET 3.5 app

我必须找到一种方法来使用公司Active Direcotries登录用户,并且我不确定是否存在没有管理员凭据(作为匿名用户)的特定连接方式-我只需要搜索用户(如果该用户存在于其中)。

我尝试了很多解决方案,但没有任何效果。 我是AD和ASP.NET的新手(但是我以前用Java进行编程)。

到目前为止,我使用的代码来自MSDN站点:

        DirectoryEntry entry = new DirectoryEntry(_path);

        try
        {
            //Bind to the native AdsObject to force authentication.
            object obj = entry.NativeObject;

            DirectorySearcher search = new DirectorySearcher(entry);

            search.Filter = "(sAMAccountName=" + username + ")";
            search.PropertiesToLoad.Add("cn");
            SearchResult result = search.FindOne();


            if (null == result)
            {
                return false;
            }

            //Update the new path to the user in the directory.
            _path = result.Path;
            _filterAttribute = (string)result.Properties["cn"][0];
        }
        catch (Exception ex)
        {
            throw new Exception("Error authenticating user. " + ex.Message);
        }

        return true;

其中路径是变量,带有指向LDAP(LDAP:/// rootDSE)的链接

主要问题是,如果我正确连接到AD,我将无法跟踪。 结果以null结尾,但是我确定我使用正确的凭据进行测试。

任何人都可以帮助或提供建议

非常感谢

你可以过去

主体上下文

像这样:

using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, myDomainTextBox.Text))
{
    // validate the credentials
    bool cIsValid = pc.ValidateCredentials(myUserNameTextBox.Text, myPasswordBox.Password);

    if (cIsValid)
    {
        // Do some stuff
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM