【发布时间】:2014-11-14 15:15:28
【问题描述】:
我想使用 .NET 3.5 中引入的 AccountManagement 命名空间来查找用户并设置他们的密码。但是,ADLDS 服务器不是我们公司域的一部分,所以我使用的是ContextType.Machine。当我搜索用户时,它从未找到(我怀疑它在错误的容器中搜索,但根据使用 ContextType.Machine 时的文档,您无法指定容器)。
using (var context = new PrincipalContext(ContextType.Machine, "test-server", null, "username", "password")) {
using (var u = UserPrincipal.FindByIdentity(context, "SuperAdmin")) {
//u is always null. :(
}
}
但是,我知道我可以使用普通的 ol' DirectoryEntry 找到用户:
using (var de = new DirectoryEntry("LDAP://test-server:389/CN=SuperAdmin,CN=SuperUsers,OU=test-server,DC=foo,DC=bar,DC=com", "username", "password", AuthenticationTypes.Secure)) {
//The user is found, but SetPassword fails with "The directory property cannot be found in the cache"
de.Invoke("SetPassword", new object[] { "foobar" });
}
最后要指出的是,我可以使用 ADSI Edit 来更改具有这些相同凭据的密码。是否可以使用较新的目录对象来执行此搜索?
【问题讨论】:
标签: c# active-directory ldap adlds