I’m trying to query the Active directory to get a list of users in my asp.net/C# application.
I have this code :
adProvider = "LDAP";
adPath = "DC00.Domain.prv/OU=Sub,OU=Users,OU=Test,DC=Domain,DC=prv";
entry = new DirectoryEntry(string.Format("{0}://{1}", adProvider, adPath),"AD","ThePwd");
DirectorySearcher searcher1 = new DirectorySearcher(entry);
searcher1 = new DirectorySearcher("objectClass=user");
SearchResultCollection results1;
results1 = searcher1.FindAll();
var list = new List<string>();
for (int i = 0; i < results1.Count; i++)
{
list.Add(results1[i].Properties["cn"][0].ToString());
}
return list;
It is working because I get a list of 1000 “common name” from users but.. In facts the Test/Users/Sub OU have only one user.. It seems the request is searching for users in the all AD range..
What is wrong?
Thanks for help
maybe I’m wrong but you overwrite the variable searcher1 twice :
This second overwrite is useless if you want to use the first one…