I have been running around like crazy trying to get this working correctly, but it seems as if it refuses to. All examples I have found on the web look pretty much like this with a difference of how the PrincipalContext, UserPrincipal, and GroupPrincipal are declared. Some are declared by a function that returns the object, others just do it directly. The frustrating part for me is that when I run this bit of code:
PrincipalContext oPrincipalContext = GetPrincipalContext(sDefaultRootOU);
UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(oPrincipalContext, IdentityType.SamAccountName, sUserName);
GroupPrincipal oGroupPrincipal = GroupPrincipal.FindByIdentity(oPrincipalContext, sGroupName);
bool isUserGroupMember = oUserPrincipal.IsMemberOf(oGroupPrincipal);
No matter what I do, isUserGroupMember always comes back as false, EVEN IF the user in question IS a member of the group. Any thoughts on what I am doing wrong? Any help would be appreciated.
Thanks!
Update This is wild, however I have managed to isolate the issue down to one group, the Domain Users group, I have verified this against other 'built in' AD groups, and the membership shows correctly. Any thoughts?