Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 C#LDAP身份验证适用于一个DC,但不适用于另一个DC_C# 4.0_Active Directory - Fatal编程技术网

C# 4.0 C#LDAP身份验证适用于一个DC,但不适用于另一个DC

C# 4.0 C#LDAP身份验证适用于一个DC,但不适用于另一个DC,c#-4.0,active-directory,C# 4.0,Active Directory,我有一个有趣的问题,这几天我一直在努力解决 我目前正在使用运行标准Active Directory实例的Windows Server 2003计算机 该目录包含两个域组件(DC),这两个域组件都是将通过我的应用程序针对该目录进行授权的内部用户 我正在使用: 作为主机名的服务器的IP地址 通过端口3269的SSL连接 GSS协商授权机制 作为两个DC的parentDN的BaseDN 将sAMAccountName作为登录名 问题是,我无法成功授权来自DC1的任何用户,但是所有属于DC2的用户都

我有一个有趣的问题,这几天我一直在努力解决

我目前正在使用运行标准Active Directory实例的Windows Server 2003计算机

该目录包含两个域组件(DC),这两个域组件都是将通过我的应用程序针对该目录进行授权的内部用户

我正在使用:

  • 作为主机名的服务器的IP地址
  • 通过端口3269的SSL连接
  • GSS协商授权机制
  • 作为两个DC的parentDN的BaseDN
  • 将sAMAccountName作为登录名
问题是,我无法成功授权来自DC1的任何用户,但是所有属于DC2的用户都非常好,工作也很好。我在DC1上遇到此错误:

8009030C:LDAPPER:DSID-0C0903E,注释:AcceptSecurityContext错误,数据0,向量
System.DirectoryServices.Protocols.LdapException:提供的凭据无效。

但是,使用Softerra的LDAP Broswer,我可以连接并授权相同的用户,而不会出现任何问题,因此我知道凭据是正确的

据我所知,这两个DC的配置相同。。。我已经浏览了他们两个的东西,任何不同的。。。但我们没有发现什么真正突出的东西

几个月前我发布了一些关于这个特殊设置的信息,我正在使用的代码也在这个线程中

这里的任何帮助都将不胜感激


谢谢

我能够让它工作,但就我的一生而言,我无法理解为什么会出现这种情况。基本上,这个错误

8009030C: LdapErr: DSID-0C09043E, comment: AcceptSecurityContext error, data 0, vece    System.DirectoryServices.Protocols.LdapException: The supplied credential is invalid.
…死了。问题是,使用我称之为DC2登录的用户需要使用域和sAMAccountName(Ex.LIB\JSmith)发布绑定,而DC1只允许输入sAMAccountName

我认为最好的编程方法是使用主体绑定帐户查询用户的DN。从这个DN,使用一些狡猾的正则表达式,我能够捕获它们从中继承的域,并发出两个单独的绑定

SearchResultEntry ResultEntry = userResponse.Entries[0];

//Let's get the root domain of the user now using our DN RegEx and that search result
Regex RegexForBaseDN = new Regex(config.LdapAuth.LdapDnRegex);
Match match = RegexForBaseDN.Match(ResultEntry.DistinguishedName);
string domain = match.Groups[1].Value;

//Try binding the user with their domain\username
try
{
    var thisUser = new NetworkCredential{
                                         Domain = domain, 
                                         UserName = username, 
                                         Password = Pin
                                        };

     //If this goes well, we'll continue forward
     ldapconn.Bind(thisUser);
}

//If that doesn't work, try biding them with the highest level domain
catch (LdapException ex)
{
     if (ex.ErrorCode.Equals(LdapErrorCodes.LDAP_INVALID_CREDENTIALS))
     {
          var thisUserOnce = new NetworkCredential{
                                                   Domain = config.LdapAuth.LdapDomain,
                                                   UserName = username,
                                                   Password = Pin
                                                  };

          //If this goes well, we'll continue forward
          ldapconn.Bind(thisUserOnce);
      }
 }
它远没有我想要的那么优雅,但它确实适用于这个特定场景

然而,我仍然很感兴趣的是,为什么命名约定会因用户从哪个DC继承而有所不同