LDAP connection in C#

1.4k views Asked by At

I am new to LDAP. I am trying to connect to LDAP using my certificate credentials and no user name and password. 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();.

When i place a breakpoint at line1 it gives the following error. base{system.DirectoryService.Protocols.DirectroyException}{"The server cannot handle directory request."}

1

There are 1 answers

0
swathi On

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.