【问题标题】:C# - How do I Get a users "Web Page" property from Active Directory?C# - 如何从 Active Directory 获取用户“网页”属性?
【发布时间】:2021-09-07 07:06:38
【问题描述】:
using System.DirectoryServices.AccountManagement;

string WebPage = "";
using (var context = new PrincipalContext(ContextType.Domain))
{
    var usr = UserPrincipal.FindByIdentity(context, System.Environment.UserName);
    if (usr != null)
        WebPage = usr.???????????;
}

我可以获取 GivenName 或 EmailAddress 之类的信息,但不能选择 Web Page 属性。我只是使用 Web Page 属性来存储用户 Slack 频道 ID 以用于直接消息,并且不希望重新利用 VoiceTelephoneNumber 属性,我可以获取并测试它可以正常工作。提前致谢!

【问题讨论】:

    标签: c# directory directoryservices


    【解决方案1】:

    对于UserPrincipal 类未公开的任何属性,您可以使用GetUnderlyingObject(),它返回底层DirectoryEntry 对象,然后从Properties 集合中获取属性。像这样:

    WebPage = ((DirectoryEntry) usr.GetUnderlyingObject()).Properties["wWWHomePage"].Value;
    

    这是我完全不理会UserPrincipal 的原因之一。无论如何,我有时不得不求助于DirectoryEntry。但也因为性能,我写了一篇关于:Active Directory: Better performance

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-08
      • 1970-01-01
      • 2017-08-05
      • 2018-05-05
      • 1970-01-01
      相关资源
      最近更新 更多