I am seriously beginning to think that where I work is cursed as far as development efforts go, I keep running into very strange issues.
I am using Roles.IsUserInRole(@"Domain\Domain Admins")
to check if a user is a Domain Administrator.
For some reason, it does not recognize me in that group, although I have been in it for years. I thought at first it MIGHT have had something to do with the space, but Roles.IsUserInRole(@"Domain\Domain Users")
works just fine. Both groups reside in the same AD OU.
Am I losing my mind or is there really something special about the "Domain Admins" group?
EDIT:
List<GroupPrincipal> result = new List<GroupPrincipal>();
PrincipalContext yourDomain = new PrincipalContext(ContextType.Domain);
UserPrincipal user = UserPrincipal.FindByIdentity(yourDomain, User.Identity.Name);
if (user != null)
{
PrincipalSearchResult<Principal> groups = user.GetAuthorizationGroups();
foreach (Principal p in groups)
{
if (p is GroupPrincipal)
{
result.Add((GroupPrincipal)p);
}
}
}
var myRoles = Roles.GetRolesForUser(User.Identity.Name);
I used the above code to verify group membership. Domain Admins
IS listed in the result
variable, but NOT in myRoles