john
john

Reputation: 1

OpenLDAP The LDAP server is unavailable

I have been trying to connect to our OpenLDAP server from asp.net for the last four days without success. Just before I pull off my hair, could any one out there have a solution that has worked( ie using c# asp.net to connect to OpenLDAP server). Apparently I can access the ldap server from putty.exe and do a search. Furthermore, I can use the LDAP server for authentication using a local installation of Drupal CMS without any problems - given that I have added the LDAP module. My problem is doing the same in asp.net. The specific details are as follows:

Ldap server is hosted on sun solaries. My development machine is running Win XP Service pack 3. The error shows up when I try to call bind with a username and password that I have used successfully with putty.

    string hostNameAndSSLPort = "ipaddress";
    string userName = "username";
    string password = "password";

    // establish a connection
    LdapConnection connection = new LdapConnection(hostNameAndSSLPort);

    // create an LdapSessionOptions object to configure session
    // settings on the connection.
    LdapSessionOptions options = connection.SessionOptions;

    options.ProtocolVersion = 3;


    options.SecureSocketLayer = true;

    connection.AuthType = AuthType.Basic;

    connection.Credential =
    new NetworkCredential(userName , password );

    try
    {
        connection.Bind();
    }
    catch(Exception e){
         lblSecurity.Text = e.Message;
    }

I have even tried starting TLS using options.StartTransportLayerSecurity(null); before calling bind by the same error persists. What could I be doing wrong? Please help!!!!!!!!

Upvotes: 0

Views: 8111

Answers (3)

Dewlife
Dewlife

Reputation: 31

I had the same issue. My fix was very similar to the answer above. The issue was the LDAP server was sending back a certificate and the client (our code) wasn't accepting it. So by adding the following line of code, made me celebrate and rip a shirt!

connection.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback((con, cer) => true);

Or in vb terms:

connection.SessionOptions.VerifyServerCertificate = New VerifyServerCertificateCallback(Function(con, cer) True)

Upvotes: 3

mayank.karki
mayank.karki

Reputation: 748

Code like this:

LdapConnection connection = new LdapConnection(new LdapDirectoryIdentifier(this._domain,     Convert.ToInt32(this._port)));
connection.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback((con, cer) => true);
connection.SessionOptions.ProtocolVersion = 3;
connection.AuthType = AuthType.Basic;       
connection.SessionOptions.SecureSocketLayer = true;

Upvotes: -1

Sam Corder
Sam Corder

Reputation: 5422

See this answer for some example code that works. How do I connect to a locally installed OpenLDAP service?

You mention using XP. I believe there is a hot fix that fixes an issue in the TLS implementation of winldap on XP. You'll have to do some searching around the microsoft site for it. I remember it being buried in a technet page somewhere.

Also don't use TLS with .net/winldap. You'll tear your hair out wondering why your web site randomly pegs out the cpu until it is killed. The answer above has an explanation. Just use SSL.

Upvotes: 0

Related Questions