【问题标题】:Get active directory user group property in asp.net website - web.config在 asp.net 网站 - web.config 中获取活动目录用户组属性
【发布时间】:2013-06-12 14:31:33
【问题描述】:

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

感谢任何帮助。

谢谢!!

【问题讨论】:

    标签: c# asp.net iis-7 active-directory web-config


    【解决方案1】:

    '我不知道您是否可以通过 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;
      }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-18
      • 2011-01-22
      相关资源
      最近更新 更多