39

I want to know what roles a logged in user belongs to without having to check the user against all possible roles (i.e. using Page.User.IsInRole())

2 Answers 2

67

using System.Web.Security;

Roles.GetRolesForUser() 

Or

Roles.GetRolesForUser(String) if not targeting the currently logged in user.

2
  • 14
    what about when the Role Manager feature has not been enabled? Jan 26, 2010 at 18:49
  • 1
    If the Role Manager feature has not been enabled, enable it in Web.config: <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider" />
    – DigitalDan
    Sep 15, 2017 at 14:33
1

try this if you want to check the currently logged in user for specific role:

Roles.IsUserInRole("Admin")
2
  • 5
    Didn't the question specifically ask for a way to avoid checking each role individually? Nov 26, 2012 at 7:59
  • Add some useful reference if you can,To explain some need information. Nov 26, 2012 at 7:59

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.