C# 中的 LDAP 连接
本文关键字:连接 LDAP 中的 | 更新日期: 2023-09-27 18:34:17
我是LDAP的新手。我正在尝试使用我的证书凭据连接到 LDAP,但没有用户名和密码。我使用的代码是
LdapConnection ldapConnection = new LdapConnection(new LdapDirectoryIdentifier("ldap://192.168.10.5:636"));
ldapConnection.AuthType = AuthType.Anonymous;
LdapSessionOptions options = ldapConnection.SessionOptions;
options.SecureSocketLayer = true;
options.ProtocolVersion = 3;
X509Certificate cert = new X509Certificate();
cert.Import(@"c:'certfolder'mycert.crt");
ldapConnection.ClientCertificates.Add(cert);
ldapConnection.Bind();
上面的代码在编译器尝试运行 ldapConnection.Bind(); 行时给我错误"LDAP 服务器不可用"。
当我在第 1 行放置断点时,它会给出以下错误。基本{系统。DirectoryService.Protocols.DirectroyException}{"服务器无法处理目录请求。
没有前缀的相同代码对我有用。
LdapConnection nconnection = new LdapConnection(new LdapDirectoryIdentifier(LDAPurl, LDAPPort));
或
LdapConnection nconnection = new LdapConnection(new LdapDirectoryIdentifier("localhost:10636"));
两者都工作正常。