0

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 !!

1 Answer 1

0

'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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.