检查 ou 中是否存在用户
我想检查某个选定的用户是否存在于 OU 中(通过他/她登录的用户名),完成此操作的最正确方法是什么? 之后我想选择用户并更改他/她的密码。
我在这里找到了一些帮助: http://www.codeproject.com/KB/ system/everythingInAD.aspx#46
但我发现的代码看起来像这样:
public static bool Exists(string objectPath) { bool found = false; if (DirectoryEntry.Exists("LDAP://" + objectPath)) { found = true; } return found; }
可以总结为:
return DirectoryEntry.Exists("LDAP://" + objectPath);
所以我真的不知道这里应该信任谁,以及如果我拥有的只是我应该传递的对象路径用户名、OU 名称和域名。
请帮忙。
谢谢。
I want check if a selected user exists within an OU (by the username he/she logs on to), what the rightest way to get this done?
After that I want to select the user and change his/her password.
I found some help here: http://www.codeproject.com/KB/system/everythingInAD.aspx#46
But the code I found looked like this:
public static bool Exists(string objectPath) { bool found = false; if (DirectoryEntry.Exists("LDAP://" + objectPath)) { found = true; } return found; }
wich could be summeried as:
return DirectoryEntry.Exists("LDAP://" + objectPath);
So I don't really know who to trust here, and what I should pass as objectPath if all I have is a username and OU name and a domain name.
Please help.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于用户名在域内必须是唯一的,因此我认为我不会过度关注 OU。构建它可能会使您的代码更加脆弱并且更加复杂。我会尝试使用新的 UserPrincipal 类如果可以的话。
Since user name need to be unique within a domain, I don't think I'd be overly concerned with the OU. Building this in could make your code more fragile and will make it more complicated. I would try using the new UserPrincipal class if you can.