如何使用PrincipalSearcher 在Active Directory 中按公用名查找单个用户?
我正在尝试使用 System.DirectoryServices 来查找用户的经理。所以我使用当前的代码来获取经理。
string test = string.Empty;
using(var context = new PrincipalContext(ContextType.Domain))
{
using(var user = UserPrincipal.FindByIdentity(context, "user"))
{
DirectoryEntry de = (DirectoryEntry)user.GetUnderlyingObject();
test = de.Properties["manager"][0].ToString();
}
}
然后,测试变量仅包含经理的 CN 或通用名称。我需要使用该通用名称来获取管理器的实际用户。因为我需要用户 ID 和电子邮件等信息。我怎样才能做到这一点?
I'm trying to use System.DirectoryServices to find the manager of a user. So I use the current code to get the manager.
string test = string.Empty;
using(var context = new PrincipalContext(ContextType.Domain))
{
using(var user = UserPrincipal.FindByIdentity(context, "user"))
{
DirectoryEntry de = (DirectoryEntry)user.GetUnderlyingObject();
test = de.Properties["manager"][0].ToString();
}
}
The test variable then contains only the CN or common name of the manager. I need to use that common name to get the actual user of the manager. Because I need things like UserID and Email etc.. How can I accomplish that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
manager
属性包含经理帐户的专有名称(通用名称只是专有名称的CN=
部分)。您可以使用
UserPrincipal.FindByIdentity( )
使用该专有名称,就像您对用户所做的那样:The
manager
attribute contains the distinguished name of the manager's account (the common name is just theCN=
portion of the distinguished name).You can use
UserPrincipal.FindByIdentity()
with that distinguished name, just like you did with the user: