Reputation: 31
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
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
Reputation: 460018
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