首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在ASP.NET 3.5应用程序中使用Active Directory/LDAP登录用户

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

Stack Overflow用户
提问于 2013-08-09 12:38:36
回答 1查看 1.6K关注 0票数 0

我必须找到一种方法,如何使用公司Active Direcotries登录用户,我不确定是否有某种方式连接没有管理员凭据(匿名)-我只需要搜索用户,如果他在那里存在。

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

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

代码语言:javascript
运行
复制
        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结尾,但我确信我使用正确的凭据进行测试。

有人能帮上忙或给你建议吗?

非常感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-09 12:48:03

你可以检查一下

PrincipalContext

如下所示:

代码语言:javascript
运行
复制
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
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18146855

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档