title: ASP.NET MVC 5 Custom Error Page
body: <p>I am using a custom authorize attribute in a <strong>ASP.NET MVC 5</strong> application like following:</p>
  
  <pre><code>public class CustomAuthorizeAttribute : AuthorizeAttribute
  {
      protected override void HandleUnauthorizedRequest(AuthorizationContext context)
      {
          if (context.HttpContext.Request.IsAuthenticated)
          {
              context.Result = new System.Web.Mvc.HttpStatusCodeResult((int)System.Net.HttpStatusCode.Forbidden);                
          }
          else
          {
              base.HandleUnauthorizedRequest(context);
          }
      }
  }
  </code></pre>
  
  <p>In <code>system.web</code> section of my web.config I mentioned error paths like:</p>
  
  <pre><code>&lt;system.web&gt;
      &lt;customErrors mode="On" defaultRedirect="/Error/Error"&gt;
        &lt;error statusCode="403" redirect="/Error/NoPermissions"/&gt;
      &lt;/customErrors&gt;
  &lt;/system.web&gt;
  </code></pre>
  
  <p>But I am never redirected to my custom error page at <code>/Error/NoPermissions</code>. Instead the browser display the general error page saying <strong>"HTTP Error 403.0 - Forbidden"</strong>.</p>