Last post Aug 17, 2009 06:03 PM by rpv
Aug 17, 2009 02:32 PM|rpv|LINK
I have to query the list of users from three domains. Following is the code written to query from one domain(this works for one domain). I need to the easiest way to do this for three domains at the same time, i.e, do I have to declare three different objects of
Directoryentry class, three different arrays to hold the connectionstring params and finally, do I have to write three different for-loops to loop through three different Search result collection ?
private DirectoryEntry de;
adConnStrSegments = ConfigurationManager.ConnectionStrings["ADConnectionString"].ConnectionString.Split(';');
de = new DirectoryEntry(adConnStrSegments, adConnStrSegments, adConnStrSegments,
DirectorySearcher Srchr = new
//Code to Populate properties for Srchr
SearchResultCollection SrchResults = Srcher.FindAll();
//Code to get the user details
Aug 17, 2009 05:44 PM|hermiod|LINK
The easiest thing to do is probably to encapsulate all of your searching code in to a single function which takes the domain credentials as parameters.
Your application calls FindUser(username)
FindUser calls another function called FindUserInDomain, passing each one the username that FindUser was given and the domain credentials for the domain it is to search.
You can then take the search results from all 3 domains and implement whatever logic you need on the results (such as combining them in to a single result, removing duplicates, etc), and then return that result to your application.
Using this method means that your application is completely ignorant to how many domains are being searched, which means you can add or remove domains and then simply modify FindUser() to make that domain searchable. The ability to search any new domains
is now automatically added to every application which uses FindUser(), which can be placed in an assembly to enable re-use.
Hope this helps
Aug 17, 2009 06:03 PM|rpv|LINK
Thanks for the response. I will try that. I was actually wondering if the directory entry or the searcher can accomodate three domains. Anyway, if nothing works, will have to go with that.