title: Redirecting an unauthorized user in identity 2.0
body: <p>For my mvc5 project i have implemented default identity but changed it according to requirements. Now i wanted to redirect unauthorized users to an view which has been created by me. I created a custom authorize filter. When an unauthorized user enters it comes to my error view. I can recognize it by the URL. But the problem is it is not showing the content in the view. Instead it is showing HTTP 404 error. I have put my code below. I know this has been asked here several times. But still i couldn't solve it. All help appreciated. Thanks in advance!</p>
  
  <pre><code>public class CustomAuthorize : AuthorizeAttribute
  {
      protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
      {
          if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
          {
              base.HandleUnauthorizedRequest(filterContext);
          }
          else
          {
              filterContext.Result = new RedirectToRouteResult(new
              RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
          }
      }
  }
  </code></pre>
  
  <p>ErrorController</p>
  
  <pre><code>public class ErrorController : Controller
  {
      // GET: Error
      public ActionResult Index()
      {
          return View();
      }
  
      public ActionResult AccessDenied()
      {
          return View();
      }
  }
  </code></pre>
  
  <p>AccessDenied view</p>
  
  <pre><code>&lt;h2&gt;AccessDenied&lt;/h2&gt;
  
  Access Denied
  </code></pre>
  
  <p>On a particular controller</p>
  
  <pre><code>[CustomAuthorize(Roles = "Admin")]
  public class ProductTypeController : Controller
  {
  }
  </code></pre>
  
  <p>Error im getting</p>
  
  <p>HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.</p>
  
  <p>UPDATED QUESTION</p>
  
  <p>Now i want to redirect Unauthorized users to ErrorView and Unauthenticated users to Login page. I have put my modified CustomAuthorise below. But it's not working. Pls guide me..</p>
  
  <pre><code>public class CustomAuthorize : AuthorizeAttribute
  {
      protected override bool AuthorizeCore(HttpContextBase httpContext)
      {
          if (!httpContext.Request.IsAuthenticated)
              return false;
          else 
              return true;
      }
      protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
      {
          filterContext.Result = new RedirectToRouteResult(new
          RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
      }
  } 
  </code></pre>