Search code examples
c#ldapdirectoryservicesnovelledirectory

Connecting to LDAP from C# using DirectoryServices


I am trying to connect to an edirectory v8.8 server running LDAP. How would I go about doing that in .NET? Can I still use the classes in System.DirectoryService such as DirectoryEntry and DirectorySearcher or are they AD specific? Do I need to specify the "Connection String" any differently?

I am trying something like the code below but it doesn't seem to work...

DirectoryEntry de = new DirectoryEntry ("LDAP://novellBox.sample.com","admin","password",AuthenticationTypes.None);
DirectorySearcher ds = new DirectorySearcher(de);
var test = ds.FindAll();

Any ideas?


Solution

  • Well, I think your connection string is missing a bit - specifying just the server name isn't good enough - you also need to specify a "starting point" for your search.

    In AD, this would typically be something like the "Users" container in your domain, which you'd specify like this in LDAP parlance:

    LDAP://novellBox.sample.com/cn=Users,dc=YourCompany,dc=com
    

    Not sure how LDAP compliant the newer versions of eDirectory are - but that should work since in theory, it's standard LDAP regardless of the implementation :-)

    But then again: only in theory, there's no difference between theory and practice.....

    There's also a System.DirectoryServices.Protocols namespace which offers low-level LDAP calls directly - and that's definitely not tied to AD at all, but it's really quite low-level.....

    There's also a Novell C# LDAP library but I've never tried it and can't say how complete or capable it is. It might give you some clues, though!

    Also see this other Stackoverflow question about Novell, LDAP and C# - it might give you additional info.