I understand that a good way to check if an user is in a role is:
if (User.IsInRole(\"Admin\"))
{
}
However How can I check if my user is
EDIT: Without coding each role, do it a LINQ extension method, like so:
private static bool IsInAnyRole(this IPrincipal user, List roles)
{
var userRoles = Roles.GetRolesForUser(user.Identity.Name);
return userRoles.Any(u => roles.Contains(u));
}
For usage, do:
var roles = new List { "Admin", "Author", "Super" };
if (user.IsInAnyRole(roles))
{
//do something
}
Or without the extension method:
var roles = new List { "Admin", "Author", "Super" };
var userRoles = Roles.GetRolesForUser(User.Identity.Name);
if (userRoles.Any(u => roles.Contains(u))
{
//do something
}