I have an MVC website in which access is based on various Roles. Once a user logs into the system they can see navigation to the pages for which they are authorized. However
Probably best way to handle this is to create an additional action filter, that redirects the user to the specified error page if he does not belong to the specified role. So, this methods will have both filters applied: [Authorize] (with no roles) to protect from unauthenticated users and redirecting them to the Login Page. And your custom Attribute with the roles. Code SIMILAR to this (not tested):
public class RoleFilterAttribute : ActionFilterAttribute
{
public string Role { get; set; }
public override void OnActionExecuting(ActionExecutingContext ctx)
{
// Assume that we have user identity because Authorize is also
// applied
var user = ctx.HttpContext.User;
if (!user.IsInRole(Role))
{
ctx.Result = new RedirectResult("url_needed_here");
}
}
}
Apply both [Authorize] and [RoleFilter] to the actions...
Hope this helps!