Search code examples
.netasp.net-mvc-3forms-authentication

.net mvc3 get roles of user


I am trying to get a list of roles for a particular user (not the current one logged in).

I figured out how to do this:

var theUser = Membership.GetUser(username)

But that just returns a MembershipUser object, which doesn't seem to have a isInRole method.

Is if I have the username as a string, how do I get a list of roles, or check that the user is in a particular role?

I am using all of the default authentication and membership providers.


Solution

  • Roles.IsUserInRole(username, role);