我试图在Active Directory中按用户名查找用户。
这有效:
const string Domain = "SLO1.Foo.Bar.biz";
const string Username = "sanderso";
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, Domain);
UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, Username);
这不是:
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);
我收到错误消息:
服务器上没有这样的对象。
这是我的ActiveDirectory设置的屏幕截图:
我也尝试过使用以下容器:
const string Container = "OU=Users,DC=SLO1,DC=Foo,DC=Bar,DC=biz";
这同样不成功。
如何在访问'用户'时指定我的容器?容器?在引入具有更复杂要求的查找之前,我尝试将其作为初始的简单设置。因此,我宁愿不满足于简单的解决方案,因为我无论如何都要对此进行故障排除,我相信。
答案 0 :(得分:8)
我明白了:)
首先,我使用以下软件来确保生成正确的容器字符串:
http://www.ldapbrowser.com/download.htm
这确认我的字符串非常正确,除了错过端口,但它只是需要一些烦恼。
正确用法是:
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);