I am trying to find a user by username in Active Directory.
It works:
const string Domain = "SLO1.Foo.Bar.biz"; const string Username = "sanderso"; PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, Domain); UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, Username);
It does not mean:
const string Domain = "SLO1.Foo.Bar.biz"; const string Container = "CN=Users,DC=SLO1,DC=Foo,DC=Bar,DC=biz"; const string Username = "sanderso"; PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, Domain, Container); UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, Username);
I get an error message:
There is no such object on the server.
here is a screenshot of my ActiveDirectory installation:

I also tried using the following container:
const string Container = "OU=Users,DC=SLO1,DC=Foo,DC=Bar,DC=biz";
it was unsuccessful.
How can I specify my container when accessing the Users container? I try to do this as an initial, simple setup before entering a search with more complex requirements. Therefore, I would prefer not to agree to a simple solution, because, as it seems to me, I still have to fix this problem.
source share