Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

Reading (Active) Directory information from outside the domain

In a recent post I described some of the basics of retrieving Active Directory information from code. Which is, using the .NET framework, no big deal. But all the code made the assumption that it was running on a machine which was a member of the domain whose Directory was being queried.

The framework classes can be used from a machine outside the domain as well. The DirectorySearcher class, which provided all the AD info, has an overloaded constructor which takes a DirectoryEntry object. This class has several overloaded constructors, several take the path to the directory. Passing in a value you can query the directory from outside the domain.

path = “LDAP://″;

DirectoryEntry adRoot = new DirectoryEntry(path);

DirectorySearcher ds = new DirectorySearcher(adRoot);

This snippet of code queries the domain controller at As you see the location is just an LDAP (Lightweight Directory Access Protocoll) URL. The DirectoryEntry class can operate against any Directory which does implement LDAP. A Windows 2000 and a Windows 2003 domain controller do. But that does not guarantee they have the same behavior. Windows 2000 is far stricter on who has the permission to query the directory, see here for details. You can pass in the credentials required for querying in another overload of the DirectoryEntry

path = “LDAP://″;

DirectoryEntry adRoot = new DirectoryEntry(path, searchUser, searchPasswd);

DirectorySearcher ds = new DirectorySearcher(adRoot);

But (again) the world does not end with just MS networks implementing LDAP. In a upcoming project we’ll have to work with a Novell domain. All I need to know is some group membership information. But having seen how different this is between the two MS implementations I’m a little worried. Any advice on the subject is appreciated.

This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.