Could not find user after specifying container for PrincipalContext

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:

enter image description here

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.

+6
source share
1 answer

I get it:)

First, I used the following software to ensure that I create the correct container string:

http://www.ldapbrowser.com/download.htm

This confirmed that my line was pretty much correct, except for the lack of a port, but for that I just had to fuss.

Proper use:

 const string Domain = "SLO1.Foo.Bar.biz:389"; const string Container = @"DC=Foo,DC=Bar,DC=biz"; const string Username = @"sanderso"; PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, Domain, Container); UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, username); 
+7
source

All Articles