简体   繁体   English

C#中的LDAP连接

[英]LDAP connection in C#

I am new to LDAP.我是 LDAP 的新手。 I am trying to connect to LDAP using my certificate credentials and no user name and password.我正在尝试使用我的证书凭据连接到 LDAP,但没有使用用户名和密码。 The code i am using is我使用的代码是

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

The above code is giving me error "The LDAP server is unavailable" when compiler tries to run line ldapConnection.Bind();.当编译器尝试运行 ldapConnection.Bind(); 行时,上面的代码给了我错误“LDAP 服务器不可用”。

When i place a breakpoint at line1 it gives the following error.当我在 line1 放置断点时,它会出现以下错误。 base{system.DirectoryService.Protocols.DirectroyException}{"The server cannot handle directory request."} base{system.DirectoryService.Protocols.DirectroyException}{“服务器无法处理目录请求。”}

Same code without prefix worked for me.没有前缀的相同代码对我有用。

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

or或者

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

Both are working fine.两者都工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM