You can get all the users roles like this:
var principal = (RolePrincipal)User;
if (!principal.GetRoles().Any())
{
// Has no roles.
}
Question
Is there a quick way to check to see if a user is not in a role?
I have an application where we are using roles but by default when you create a user, that user does not get assigned a role. I want to set a check on a method that says
if user does not have a role - redirect to another page.
I can easily check if the user is in a specific role but I cannot seem to find a way to check if a user doesn't have a role at all.
Thanks for any help.
La solution
You can get all the users roles like this:
var principal = (RolePrincipal)User;
if (!principal.GetRoles().Any())
{
// Has no roles.
}