title: MVC 5 - Role Authorization - Custom unauthorized page
body: <p>I am using role-based authorization and I have made this class to handle redirection to a custom view when they dont have the right role.</p>
  
  <pre><code>public class MyAuthorizeAttribute : AuthorizeAttribute
      {
          protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
          {
              if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
              {
                  base.HandleUnauthorizedRequest(filterContext);
              }
              else if (!this.Roles.Split(',').Any(filterContext.HttpContext.User.IsInRole))
              {
  
                  filterContext.Result = new ViewResult
                  {
                      ViewName = "~/Views/Shared/_Unauthorized.cshtml"
                  };
              }
              else
              {
                  base.HandleUnauthorizedRequest(filterContext);
              }
          }
      }
  </code></pre>
  
  <p>And I just add it to each controller action like this:</p>
  
  <pre><code>[MyAuthorize(Roles = "Admin")]
  </code></pre>
  
  <p>This works fine but I would like to get some more info on my unauthorized page. 
  So the question is how I pass info like which page they where trying to accesss, what role is needed and which roles they already have.
  Where do I do this? In the MyAuthorizeAttribute class? And how do i pass the info to the view?</p>