views:

2104

answers:

1

I need to be able to get a list of the groups a user is in, but I need to have one/some/all of the following properties visible:

  • distinguishedname
  • name
  • cn
  • samaccountname

What I have right now returns some sort of name, but not any of the ones above (the names seem close, but don't all match correctly. This is what I am using:

ArrayList groups = new ArrayList();
foreach (System.Security.Principal.IdentityReference group in System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups)
    groups.Add(group.Translate(typeof(System.Security.Principal.NTAccount)));

Like I said, the above works, but will not get me the proper names I need for my program (the ones specified above). I need this to be able to match up with the list I get while calling all of the groups in my domain:

DirectoryEntry dirEnt = new DirectoryEntry("LDAP://my_domain_controller");
DirectorySearcher srch = new DirectorySearcher(dirEnt);
srch.Filter = "(objectClass=Group)";
var results = srch.FindAll();
+2  A: 

You cannot do this in one step, as groups are also separate AD entries with properties.

So in the first run you should get the group names a user is in and fill them in a list of some kind.

The second step is to go through all of the group names and query them one by one to get the group properties (like distinguishedname, and so on) and collect it to some kind of structure.

Biri