I’m using Membership Provider in my ASP.NET MVC Application . I want to check a user is admin or not .
if (Membership.ValidateUser(model.UserName, model.Password))
{
....
}
ValidateUser gets only Username and Password , I want to add another field ( IsAdmin ) . how can I write this code ?!
As @jsalvy reminded me, you can just do this:
The
IsUserInRolewill return true if the user is in the role or false if not. You can also usestring[] userRoles = Roles.GetRolesForUser(userName);to get all the roles a user is in. And you can use the[Authorize(Roles = "Admin")]attribute to restrict access to anyone who is not an admin.