hhjj
hhjj

Reputation: 31

How do I get the roles of a user using the Membership class

I want to create a Login.aspx page by using the Membership class. I check the username and password by using Membership.ValidateUser(txtUsern.Text, txtPass.Text) and now I want to get the role of this user. Is there a method in the Membership class to get the role of the user?

Thank you....

Upvotes: 0

Views: 268

Answers (2)

Brij
Brij

Reputation: 13129

You should use the following code

string[] roles = Roles.GetRolesForUser("userName");

The above roles string array will contain all the roles for your user. Besides this if the user is logged in you can check if the user is in a particular role or not using

if(Roles.IsUserInRole("Admin"))
{
//your code
}

here "Admin" is the role.

Upvotes: 1

Tim Schmelter
Tim Schmelter

Reputation: 460018

Roles.GetRolesForUser Method

String[] roles = Roles.GetRolesForUser(); // roles of currently logged-on user

or

roles = Roles.GetRolesForUser(userName); // roles of the user with the specified username

Upvotes: 2

Related Questions