我已经在我的机器上安装了 OpenLDAP for Windows,但无法从我的 ASP.NET 应用程序连接到我的本地 LDAP 服务器。
我在代码中的第一步是创建一个新的 DirectoryEntry 实例:
DirectoryEntry entry = new DirectoryEntry("LDAP://maxcrc.com");
它抛出一个异常,提示“服务器无法运行”
我已经尝试过 LDAP 客户端程序,它们似乎可以很好地连接到本地主机或 (127.0.0.1) 与以下 DC:
DC=maxcrc,DC=com
我尝试了几种连接方式,但没有包括(LDAP://localhost、LDAP://DC=maxcrc,DC=com 或 LDAP://localhost/DC=maxcrc,DC=com)
最佳答案
如果我没记错的话,通过DirectoryEntry
连接时需要指定端口号:
DirectoryEntry entry = new DirectoryEntry("LDAP://localhost:389");
但是,我建议您查看 System.DirectoryServices.Protocols
命名空间,以实际促进服务器连接,尤其是 LdapConnection
类 - this question是一个很好的起点,并且很好地说明了这种方法的好处。
此外,请记住,通过端口 389(ldap 与 ldaps)的流量将采用纯文本形式,这在诊断连接问题时非常有用。 Wireshark在这种情况下是您最好的 friend ,并且内置了专门用于 LDAP 通信的 TCP 过滤器。
关于c# - 无法连接到我的本地 LDAP 服务器 : "the server is not operational",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35796643/