You must start another search using the following search filter
string.Format("(&(objectCategory=group)(objectClass=group)(primaryGroupToken={0}))", singleRes.Properties["primaryGroupID"]);
primaryGroupTokenis a computed attribute that is automatically created by Active Directory when a group is created. primaryGroupIDassigned to the user saves this value.
, , UserPrincipal.GetGroups . , .NET 3.5 .
using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "yourdomain.com"))
{
using (UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "YourUser"))
{
foreach (Principal p in user.GetGroups())
{
Console.WriteLine(p.Name);
}
}
}
GetGroups , , . , GetAuthorizationGroups.