LDAP Support in the .NET Framework

I use System.DirectoryServices to query the active directory for authentication / retrieve user information in a winforms application. Something like below:

 var path = "LDAP://" + domain; var entry = new DirectoryEntry(path); DirectorySearcher myDirectorySearcher = new DirectorySearcher(entry); var filter = string.Format("(&(ObjectClass={0})(sAMAccountName={1}))", "person", username); myDirectorySearcher.Filter = filter; 

I can only verify this code in an Active Directory company. Will it work on any technology that supports LDAP ?

+4
source share
3 answers

The System.DirectoryServices namespace is optimized for Active Directory. It will work against other LDAP servers with certain limitations.

There's also System.DirectoryServices.Protocols (see the MSDN documentation and the introduction of the MSDN article ) namespace (new in .NET 2.0), which is a lower-level implementation of LDAP - you need to work harder and write more code, but it's more portable and more likely total will work with other LDAP repositories.

There is also System.DirectoryServices.AccountManagement (see the MSDN documentation ) - a namespace (new in .NET 3.5) that is much more convenient and easy to use Active Directory.NET - much better than SDS! But this is Active Directory, as far as I can tell.

+7
source

You must change the filter to look like this:

var filter = string.Format("(&(objectCategory={0})(objectClass={1})(sAMAccountName={2}))", "person", "user", username);

However, this will not work in any LDAP directory. sAMAccountName , for example, is an AD-specific attribute.

+1
source

The last time I tried to use system.directoryservices on a Novell network, it just didn't work completely, exceptions were thrown everywhere. Sorry, I could not be more specific with version numbers.

0
source

Source: https://habr.com/ru/post/1388909/


All Articles