Reputation: 6781
I know you can use User.IsInRole
to check to see if a user is in a specific role but is there a way to display what role the user is in when you don't know the role names?
Upvotes: 0
Views: 26
Reputation: 6023
The ASP.NET Roles Provider has a method to return all Roles for the current user or for a specified UserName.
string[] rolesArray;
rolesArray = Roles.GetRolesForUser();
It is worth noting that if you call the method with no UserName parameter AND there is currently no one signed in (Anonymous access) then the method will THROW an exception.
Here are links to doc for both call variations:
http://msdn.microsoft.com/en-us/library/8ak75t41(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/8h930x07(v=vs.110).aspx
Upvotes: 2