简体   繁体   中英

Get active directory user group property in asp.net website - web.config

In my asp.net website, I am using ActiveDirectoryRoleProvider in my web.config. I would like to get active directory user group properties like ( group name, group description...) in my site. As there any way I can solve this by using web.config ?

Any help is appreciated.

Thanks !!

'I don't know if you can get this information by a web.config setting, but you can get this information from the System.DirectoryServices.AccountManagement namespace. (if you're looking per user)

You could store the domain name in the appsettings of the web.config and do something like...

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;
  }

The above will give you a list of groups a user belongs to, you could go deeper and get more info, but I think that's what you're trying to accomplish.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM