Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net membership - how to determine programmatically is user is in role

What is the code for determining if a user is in a role?

I have set up all the users through the ASP.NET Configuration Security tab but now want to put logic around some key areas so only people in certain roles can see and access these areas.

like image 672
leora Avatar asked Jul 31 '09 17:07

leora


3 Answers

if (User.IsInRole("rolename")) {
  // my action
}
like image 151
Chris Van Opstal Avatar answered Nov 07 '22 14:11

Chris Van Opstal


Easy~

HttpContext.Current.User.IsInRole("roleName")
like image 34
BigBlondeViking Avatar answered Nov 07 '22 14:11

BigBlondeViking


Check out the Roles class, specifically IsUserInRole, GetUsersInRole, AddUserToRole, etc.

I use these all the time.

like image 3
Matthew Jones Avatar answered Nov 07 '22 14:11

Matthew Jones