Request the active directory to get user roles in .NET.

I used Linq in Active Directory , but it’s hard for me to get a list of all the roles that the user is a member of. I can get a list of their closest groups, but it's not recursive.

The reason I'm trying to request the AD directory is to bypass the AspNetWindowsTokenRoleProvider built-in role manager, which will not let you call Roles.GetRolesForUser (username) if the username does not match the current Windows authentication system.

+3
source share
2 answers

Have you watched this ?

+1
source

.NET 3.5 , System.DirectoryServices.AccountManagement (S.DS.AM). :

.NET Framework 3.5

, / AD:

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

if(user != null)
{
   // find the roles....
   var roles = user.GetAuthorizationGroups();

   // enumerate over them
   foreach (Principal p in roles)
   {
       // do something
   }
}

S.DS.AM AD:

+16

All Articles