1

前提是,这是我第一次使用 Active Directory(我的项目是 Asp.Net MVC 中的 Web 应用程序)。

对于 Active Directory 中的用户,我需要读取givenNameC# 中的属性。

我的问题:

  1. 在 Windows Server 上使用 Active Directory 浏览器我看不到givenName用户的属性。能否从 Active Directory 的视图中隐藏此属性?

  2. 你能给我提供一个代码示例,让我givenName知道用户的 UserName 属性吗?

4

1 回答 1

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 中与用户和组一起玩变得非常容易!

于 2012-10-12T08:59:00.310 回答