Sea*_*son 7 c# active-directory userprincipal
我正在尝试在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);
Run Code Online (Sandbox Code Playgroud)
这不是:
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);
Run Code Online (Sandbox Code Playgroud)
我收到错误消息:
服务器上没有这样的对象.
这是我的ActiveDirectory设置的屏幕截图:

我也尝试使用以下Container:
const string Container = "OU=Users,DC=SLO1,DC=Foo,DC=Bar,DC=biz";
Run Code Online (Sandbox Code Playgroud)
这同样不成功.
如何在访问"用户"容器时指定我的容器?在尝试引入更复杂的需求之前,我尝试将其作为初始的简单设置.所以,我宁愿不满足于这个简单的解决方案,因为我无论如何都要对此进行故障排除,我相信.
我想到了 :)
首先,我使用以下软件来确保生成正确的容器字符串:
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13359 次 |
| 最近记录: |