【发布时间】:2019-10-09 21:53:15
【问题描述】:
我有一些 .NET 工作代码(作为桌面应用程序和 IIS 部署)来从 LDAP 读取数据:
string ldapUrl = "LDAP://myLdapUrl.example/ou=user,dc=MyDC";
AuthenticationTypes auth = AuthenticationTypes.None;
using (DirectoryEntry directoryEntry = new DirectoryEntry(
ldapUrl,
"cn=ldap_user,ou=user,dc=MyDC",
"NotMyTruePassword",
auth)
{
using (DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry))
{
directorySearcher.PropertiesToLoad.AddRange(new[] { "uid", "givenname", "sn", "middlename", "description", "memberof" });
directorySearcher.Filter = String.Format("(&(objectclass=person)(cn={0}))", user);
directorySearcher.SearchScope = SearchScope.OneLevel;
directorySearcher.SizeLimit = 10;
SearchResult searchResult = directorySearcher.FindOne();
}
}
但是当我尝试连接到 LDAPS 端口 (636) 时,它会失败并显示
System.Runtime.InteropServices.COMException (0x8007203A):服务器无法运行。
注意事项:
我已通过 MMC 将服务器 CA 添加到我的帐户中。
之后,我可以使用 LdapAdmin 连接到 LDAPS 端口。
-
我尝试了以下更改:
-
只需将端口添加到服务器 URL1:
string ldapUrl = "LDAP://myLdapUrl.example:636/ou=user,dc=MyDC"; -
添加端口并将authTypes更改为
SecureSocketsLayer2:string ldapUrl = "LDAP://myLdapUrl.example:636/ou=user,dc=MyDC"; AuthenticationTypes auth = AuthenticationTypes.SecureSocketsLayer; -
添加端口并将authType更改为
Secure2:string ldapUrl = "LDAP://myLdapUrl.example:636/ou=user,dc=MyDC"; AuthenticationTypes auth = AuthenticationTypes.Secure;
-
而且我总是得到相同的结果。
我找到了一些直接使用 LDAP 连接的示例(来自 System.DirectoryServices.Protocols),但我不想更改代码,因为我已经让它工作了。
1 我经常看到有人声称我应该将
LDAP:// 更改为LDAPS:,但似乎DirectoryServices 不是这样工作的。在任何情况下也失败了。
2 我很确定这两个选项是用于身份验证而不是用于设置 SSL 连接,但我还是尝试了它们。
【问题讨论】:
标签: c# .net ssl ldap directoryservices