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

leora picture leora · Jul 31, 2009 · Viewed 18.8k times · Source

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.

Answer

Chris Van Opstal picture Chris Van Opstal · Jul 31, 2009
if (User.IsInRole("rolename")) {
  // my action
}