[英]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.