Reputation: 12190
I'm using DirectorySearcher
to try to find information about users. When I try to run it on the server (which is located in Germany), it retrieves the expected information about users in Germany but not about users from any other countries.
Here's my code:
DirectorySearcher searcher = new DirectorySearcher();
searcher.Filter = $"(mail={user.email})";
SearchResult sr = searcher.FindOne();
Has anyone seen something like this? Is it a programming error, or could it be something about the server configuration?
For what it's worth, the server is running Windows Server 2008. I access it via Windows Terminal Service. I did confirm that Active Directory appears to work properly on the server - when I go to Windows's Active Directory Search utility and search for the same email address, I'm able to locate the user as expected.
I'm not an administrator on the server (someone else administers it). With that said, if the problem's likely the server, what should I ask/tell the administrator? What kinds of things could cause that, and what kind of changes might I have to make?
Upvotes: 2
Views: 372
Reputation: 7465
If you are in a multi-domain environment, you have to get all the domains belonging to your forest and search them all:
List<System.DirectoryServices.AccountManagement.PrincipalContext> contexts = new List<System.DirectoryServices.AccountManagement.PrincipalContext>();
System.DirectoryServices.ActiveDirectory.Forest f = System.DirectoryServices.ActiveDirectory.Forest.GetCurrentForest();
foreach (System.DirectoryServices.ActiveDirectory.Domain dom in f.Domains)
contexts.Add(new System.DirectoryServices.AccountManagement.PrincipalContext(DirectoryServices.AccountManagement.ContextType.Domain, dom.Name));
You have to search ALL of these principal contexts.
Here's an example of searching PrincipalContext object, but you'll have to do this for each one: Getting all users from Active Directory PrincipalContext
Upvotes: 2