繁体   English   中英

C# - 如何从 Active Directory 获取用户的“网页”属性?

[英]C# - How do I Get a users "Web Page" property from Active Directory?

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 属性。 我只是使用网页属性来存储用户用于直接消息的 Slack 频道 ID,并且不希望重新调整 VoiceTelephoneNumber 属性的用途,我可以获取并测试该属性是否有效。 提前致谢!

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

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

这是我根本UserPrincipal原因之一。 无论如何,我有时不得不求助于DirectoryEntry 也是因为性能,我写了一篇关于: Active Directory:更好的性能

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM