locked
LDAP C#.NET question RRS feed

  • Question

  • User1122023049 posted

    I'm using C#.NET to connect to an email directory on an LDAP server for the purposes of searching/retrieving and adding email contacts.  I'm using freeldap.org which i believe is NOT an active directory server.  I'm trying to figure out how to use C# code to connect to the LDAP server.  Freeldap supports SSL and TLS.  I've found several examples on the web as to how to use LDAP, but none seem to work for my setup.  freeldap gives the following information to access their system:

    LDAP Server      ds1.us.freeldap.org
    Search base     uid=username , ou=People, o=entic.net
    Port     636 (encrypted over SSL)
    Bind DN*     uid=username , ou=People, o=entic.net

    So far i've tried the following

    DirectoryEntry.Path = "ldaps://ds1.us.freeldap.org:636/" and "ldaps://ds1.us.freeldap.org:636/ou=People, o=entic.net" and just "ds1.us.freeldap.org:636" ... also tried port 389 in case it connects over TLS
    DirectoryEntry.Username = myUsername and tried the Bind DN
    DirectoryEntry.AuthenticationType = AuthenticationTypes.SecureSocketsLayer; (not sure if there is one for TLS)
    DirectoryEntry.Password = myPassword

    Finally i attempt to get results with:

    SearchResultCollection res = DirectorySearcher.FindAll();

    No matter what all i get is the follow error: {"Unknown error (0x80005000)"}.  I search only reveals stuff on Active Directory implementations..

    I'm using VS2008 and this project uses .NET 2.0

    Any idea how to implement LDAP with bind DN and SSL?

    thanks!

    Monday, July 13, 2009 4:29 PM

All replies

  • User-517928126 posted

     Have you tried connecting without using SSL (LDAP://) - just to simplify things?  Not sure if this post might help: http://bytes.com/topic/net/answers/628481-accessing-ms-ad-using-ssl-ldaps

    Tuesday, July 14, 2009 3:38 PM
  • User1122023049 posted

    Good point.  i tried it w/o SSL and got the same problem.  I tried "ldap://" and got the same error.  I tried it with no prefix and it returns "unspecified error" on FindAll().  I stripped my code down to this:

    DirectoryEntry de = new DirectoryEntry("ldap://" + ldap_host + "/" + ldap_search, ldap_dn, ldap_password);
    DirectorySearcher ds = new DirectorySearcher(de);
    ds.Filter = ("(objectClass=user)");
    SearchResultCollection collection = ds.FindAll();

    The error occurs on the last line...

    Tuesday, July 14, 2009 11:20 PM