简体   繁体   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.???????????;
}

I am able to get things like GivenName or EmailAddress, but the Web Page property is not an option.我可以获取 GivenName 或 EmailAddress 之类的信息,但不能选择 Web Page 属性。 I am just using the Web Page property to store the users Slack channel ID for direct messages and would prefer not to repurpose the VoiceTelephoneNumber property, which I can acquire and have tested as working.我只是使用网页属性来存储用户用于直接消息的 Slack 频道 ID,并且不希望重新调整 VoiceTelephoneNumber 属性的用途,我可以获取并测试该属性是否有效。 Thanks in advance!提前致谢!

For any attribute that is not exposed by the UserPrincipal class, you can use GetUnderlyingObject() , which returns the underlying DirectoryEntry object, then get the attribute from the Properties collection.对于UserPrincipal类未公开的任何属性,您可以使用GetUnderlyingObject() ,它返回基础DirectoryEntry对象,然后从Properties集合中获取该属性。 Like this:像这样:

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

This is one reason I don't bother with UserPrincipal at all.这是我根本UserPrincipal原因之一。 I have to resort to DirectoryEntry sometimes anyway.无论如何,我有时不得不求助于DirectoryEntry But also because of performance, which I wrote an article about: Active Directory: Better performance也是因为性能,我写了一篇关于: Active Directory:更好的性能

暂无
暂无

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

相关问题 如何使用C#从Active Directory中检索用户列表? - How do I retrieve a list of users from Active Directory using C#? 我如何使用 C# 从活动目录中获取 SID-History 值 - How do i get the SID-History value using c# from active directory 如何从使用C#的用户名获取存储在Active Directory中的真实姓名? - How do I get a real name stored in Active Directory from an username with C#? 从 C# web 页面(包括 IIS)获取当前登录的 Active Directory 用户 - Get currently logged-on Active Directory user from a C# web page (IIS incl) C# Active Directory - 如何从注册服务目录 object 加载“certificateTemplates”属性? - C# Active Directory - How can I load the “certificateTemplates” Property from an Enrollment Services directory object? 如何在 C# 中从 Active Directory 获取用户并将其显示在 ComboBox 中 - How to get users from Active Directory in C# and display them in a ComboBox 如何在C#Web应用程序中找到用户的Active Directory显示名称? - How do I find a user's Active Directory display name in a C# web application? C# Active Directory:获取所有用户的主目录路径 - C# Active Directory: Get home directory path of all users 如何从活动目录中获取用户列表? - How can I get a list of users from active directory? 从 C# 应用程序打开 Active Directory 用户和计算机属性表 - Open Active Directory Users and Computers Property Sheet from a C# Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM