【问题标题】:Active Directory authentication in ASP.NETASP.NET 中的 Active Directory 身份验证
【发布时间】:2012-10-03 17:15:18
【问题描述】:

我正在尝试实现活动目录身份验证,但我遇到了异常,就像

System.Runtime.InteropServices.COMException was caught
  Message=Unknown error (0x80005000)
  Source=System.DirectoryServices
  ErrorCode=-2147463168
  StackTrace:
       at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
       at System.DirectoryServices.DirectoryEntry.Bind()
       at System.DirectoryServices.DirectoryEntry.get_AdsObject()
       at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
       at System.DirectoryServices.DirectorySearcher.FindOne()
       at ConsoleApplication1.ADAuthentication.AuthenticateADUsers(String userNameWithDomain, String password) in C:\Users\awadhendrat\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 83
       at ConsoleApplication1.Program.Main(String[] args) in C:\Users\awadhendrat\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 23
  InnerException: 

我不知道我错过了什么。以下是我为实现 AD 身份验证而编写的代码。

public bool AuthenticateADUsers(string userNameWithDomain, string password)
        {
            DirectoryEntry objDirectoryEntry = null;
            DirectorySearcher objDirectorySearcher = null;

            try
            {
                objDirectoryEntry = new DirectoryEntry("https://ab.hotels.com/", userNameWithDomain, password, AuthenticationTypes.Delegation);
                objDirectorySearcher = new DirectorySearcher(objDirectoryEntry);
                objDirectorySearcher.Filter = string.Format("(&(objectClass=user)(objectCategory=user) (sAMAccountName={0}))", userNameWithDomain.Substring(0, userNameWithDomain.IndexOf('@')));
                objDirectorySearcher.PropertiesToLoad.Add("msRTCSIP-PrimaryUserAddress");
                var result = objDirectorySearcher.FindOne();
                if (result != null)
                    return true;
                else
                    return false;                           
            }
            catch
            {
                throw;
            }
        }

我做了一些谷歌,但没有得到帮助。在这里,我几乎没有像他们写 LDAP://somedomain/ 的每个地方那样混淆,但在这里我有https://somedomain.com 另一个混淆是我的测试应用程序在一个域上,并且提供的域在另一台服务器上。

当我打开客户端提供的用于 AD 身份验证的链接时,它会打开 Open Office Web Access。

我不知道如何解决这个问题。

谢谢。

【问题讨论】:

    标签: c# c#-4.0 active-directory c#-3.0


    【解决方案1】:

    根据this answer(以及我为测试它而编写的一些快速代码),这是一个权限问题(可能与您对 AD 路径使用 https URL 有关,请查看this code 以构建DirectoryEntry 或事实上,您正在使用您尝试验证的同一用户进行完整的 AD 搜索)。

    【讨论】:

    • 好的。我有一个困惑,我可以对不同的域使用 AD 身份验证,比如我在 A 域上创建应用程序,而 Active Directory 在 B 域上。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多