![](/img/trans.png)
[英]How do I retrieve a list of users from Active Directory using C#?
[英]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.