canuckconsulting
asked on
.Net 4.5 application: Unable to determine Active Directory Group membership for nested groups
I have an ASP.Net 4.5 application using integrated security. I have no problem finding the groups the logged in user is directly a member off but am unable to return the groups they are a member of via nested group membership.
The code below returns only user who are directly a member of the group:
And this code returns only groups the user is directly a member of:
How can I retrieve all the users associated with a given group or all the groups associated with a given user?
Ideally I want to ask "Is this user a member of this group" like the functionality the IsMemberOf() provides. This is how I started this only to find that the method does not support nested groups either.
The code below returns only user who are directly a member of the group:
var MyDomain = new PrincipalContext(ContextType.Domain, "MyDomain");
GroupPrincipal grp = GroupPrincipal.FindByIdentity(MyDomain, IdentityType.Name, "MyGroupName");
foreach (var p in grp.GetMembers(true))
testing += p.Name + "<br>";
And this code returns only groups the user is directly a member of:
var MyDomain = new PrincipalContext(ContextType.Domain, "MyDomain");
UserPrincipal usr = UserPrincipal.FindByIdentity(MyDomain, Request.LogonUserIdentity.Name);
foreach (var p in usr.GetGroups())
testing += "<br>" + p.Name;
How can I retrieve all the users associated with a given group or all the groups associated with a given user?
Ideally I want to ask "Is this user a member of this group" like the functionality the IsMemberOf() provides. This is how I started this only to find that the method does not support nested groups either.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER