【发布时间】:2018-05-03 07:52:47
【问题描述】:
我在尝试使用 LdapConnection 类绑定到特定 DC 时遇到了一个奇怪的错误。我设法将代码精简为以下内容:
static void Main(string[] args)
{
var cred = new NetworkCredential("username", "password", "domainFQDN");
try
{
var ldapConnection = new LdapConnection(new LdapDirectoryIdentifier("domain1.test.local", 389, false, false), cred, AuthType.Kerberos);
ldapConnection.Bind();
Console.WriteLine("Connected 1");
}
catch (Exception e)
{
Console.WriteLine(e);
}
try
{
var ldapConnection2 = new LdapConnection(new LdapDirectoryIdentifier("dc1.domain1.test.local", 389, true, false), cred, AuthType.Kerberos);
ldapConnection2.Bind();
Console.WriteLine("Connected 2");
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadLine();
}
这个程序的输出是一致的:
Connected 1
System.DirectoryServices.Protocols.LdapException: A local error occurred.
at System.DirectoryServices.Protocols.LdapConnection.BindHelper(NetworkCredential newCredential, Boolean needSetCredential)
at System.DirectoryServices.Protocols.LdapConnection.Bind()
调用之间的唯一区别是,在第一个连接中我使用LdapDirectoryIdentifier 中的域 FQDN,而在第二个连接中我使用确切的 DC 地址。当然,我验证了第一个连接与第二个连接到同一个 DC。
该错误仅在我为身份验证方法指定AuthType.Kerberos 时发生。当我尝试连接到不同林中的域时,总是会出现该错误,并且仅在我连接到本地林中的 DC 时才会出现。
我可能可以通过使用该域名两次来解决该错误,但一旦连接到特定 DC,我将无法确保粘性。
如何确保第二个连接转到同一个 DC 而不会出现此错误?
【问题讨论】:
标签: .net active-directory ldap kerberos