gpt4 book ai didi

c# - 如何从员工的 UserPrincipal 对象获取经理的 UserPrincipal 对象

转载 作者:太空宇宙 更新时间:2023-11-03 23:16:37 25 4
gpt4 key购买 nike

我有一个 Active Directory 搜索器,可以使用 UserPrincipal 对象获取用户的详细信息。我正在使用 System.DirectoryServicesSystem.DirectoryServices.AccountManagement 并且它通过上下文访问 AD。

但是,我还需要将用户的经理作为单独的 UserPrincipal 对象获取。最直接的方法是什么?

我已经尝试了以下方法,但不幸的是,转换不起作用:

DirectoryEntry directoryEntry = (DirectoryEntry)userPrincipal.GetUnderlyingObject();
UserPrincipal manager = (UserPrincipal)directoryEntry.Properties["manager"][0];

我希望每个 UserPrincipal 对象中都有一个名为 UsersManagerUserPrincipal 属性,但我找不到它,所以我猜没有这样的东西。

谢谢!

最佳答案

manager 属性将为您提供经理帐户的专有名称,它只是一个字符串。因此,您必须使用该 DN 查找经理的帐户。

这可能有效(假设您已经有一个 context 对象):

UserPrincipal manager = UserPrincipal.FindByIdentity(context, IdentityType.DistinguishedName, directoryEntry.Properties["manager"][0].ToString());

关于c# - 如何从员工的 UserPrincipal 对象获取经理的 UserPrincipal 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37051534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com