title: ASP.NET MVC 6 handling errors based on HTTP status code
body: <p>I want to display different error messages for each status code e.g:</p>
  
  <ul>
  <li>400 Bad Request</li>
  <li>403 Forbidden</li>
  <li>500 Internal Server Error</li>
  <li>404 Not Found</li>
  <li>401 Unauthorized</li>
  </ul>
  
  <p>How can I achieve this in the new ASP.NET MVC 6 applications? Can I do this using the built in UseErrorHandler method?</p>
  
  <pre><code>application.UseErrorHandler("/error");
  </code></pre>
  
  <p>Also, I noticed that even with the above handler, entering a non-existent URL e.g. /this-page-does-not-exist, causes an ugly 404 Not Found error page from IIS. How can this also be handled?</p>
  
  <p>In MVC 5 we have had to use the system.web customerrors section for ASP.NET <strong>and</strong> the system.webServer httpErrors section in the web.config file but it was difficult to work with an unwieldy, with lots of very strange behaviour. Does MVC 6 make this a lot simpler?</p>