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.
if (User.IsInRole("rolename")) {
// my action
}
Easy~
HttpContext.Current.User.IsInRole("roleName")
Check out the Roles class, specifically IsUserInRole, GetUsersInRole, AddUserToRole, etc.
I use these all the time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With