C#中的LDAP连接

时间:2014-12-15 09:46:32

标签: c# ldap ldapconnection

我是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();

以上代码给出了错误" LDAP服务器不可用"当编译器尝试运行行ldapConnection.Bind();。

当我在第1行放置一个断点时,会出现以下错误。 base {system.DirectoryService.Protocols.DirectroyException} {"服务器无法处理目录请求。"}

1 个答案:

答案 0 :(得分:0)

没有前缀的相同代码对我有用。

LdapConnection nconnection = new LdapConnection(new LdapDirectoryIdentifier(LDAPurl, LDAPPort));

LdapConnection nconnection = new LdapConnection(new LdapDirectoryIdentifier("localhost:10636"));

两个都工作正常。