0

在我的 asp.net 网站中,我在 web.config 中使用 ActiveDirectoryRoleProvider。我想在我的站点中获取活动目录用户组属性,例如(组名、组描述...)。有什么办法可以通过使用 web.config 解决这个问题?

任何帮助表示赞赏。

谢谢 !!

4

1 回答 1

0

'我不知道您是否可以通过 web.config 设置获取此信息,但您可以从 System.DirectoryServices.AccountManagement 命名空间获取此信息。(如果您正在查看每个用户)

您可以将域名存储在 web.config 的 appsettings 中并执行类似...

private static PrincipalContext _ctx = new PrincipalContext(ContextType.Domain, System.Configuration.ConfigurationManager.AppSettings["DomainName"]);

  public List<string> UserGroups(string userName)
  {
    List<string> ret = new List<string>();
    using (UserPrincipal user = UserPrincipal.FindByIdentity(_ctx, userName))
    {
      if (user != null)
      {
        foreach (Principal p in user.GetAuthorizationGroups())
        { 
          ret.Add(p.Name);
        }
      }
    }
    return ret;
  }

以上将为您提供用户所属组的列表,您可以更深入并获取更多信息,但我认为这就是您想要完成的。

于 2013-06-12T14:47:09.310 回答