2012-10-12 126 views
1

前提是,这是我第一次使用Active Directory(我的项目是Asp.Net MVC中的Web应用程序)。Active Directory如何查看隐藏属性

对于Active Directory中的用户,我需要在我的C#中读取属性givenName

我的问题:

  1. 使用Active Directory浏览器在Windows服务器上,我不能看到用户givenName属性。此属性可以在Active Directory中的视图中隐藏吗?

  2. 你能否给我提供一个代码示例,它允许我知道用户的用户名为givenName属性?

回答

3

如果你在.NET 3.5及以上,你应该看看System.DirectoryServices.AccountManagement(S.DS.AM)命名空间。在这里阅读全部内容:

基本上,你可以定义域范围内,并可以轻松地查找用户和/或组AD:

// set up domain context 
PrincipalContext ctx = new PrincipalContext(ContextType.Domain); 

// find a user 
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName"); 

if(user != null) 
{ 
    // do something here.... 
    string givenName = user.GivenName;  
} 

的新的S.DS.AM可以很容易地与AD中的用户和群组玩耍!

+0

我能回答我的第一个问题看完这篇文章http://www.stuartclowes.com/2011/10/displaying-hidden-attributes-in-active.html – GibboK

+0

你的代码示例是许多伟大的感谢! – GibboK

相关问题