Determining user's groups RRS feed

  • Question

  • User-1129879462 posted

    Is there a way to determine a user's groups?


    Friday, October 28, 2016 7:19 PM

All replies

  • User-2057865890 posted

    Hi Krisrajz,

    We are using System.DirectoryServices namespace to perform a search on AD.

    The System.DirectoryServices.AccountManagement namespace provides uniform access and manipulation of user, computer, and group security principals.

    using System.DirectoryServices.AccountManagement;
    public List<string> GetGroupNames(string userName)
        var pc = new PrincipalContext(ContextType.Domain);
        var src = UserPrincipal.FindByIdentity(pc, userName).GetGroups(pc);
        var result = new List<string>();
        src.ToList().ForEach(sr => result.Add(sr.SamAccountName));
        return result;

    reference: http://stackoverflow.com/a/5310317 

    Best Regards,


    Monday, October 31, 2016 9:57 AM