title: Displaying a 404 Not Found Page for ASP.NET Core MVC
body: <p>I am using the middle-ware below to set up error pages for HTTP status codes 400 to 599. So visiting <code>/error/400</code> shows a 400 Bad Request error page.</p>
  
  <pre><code>application.UseStatusCodePagesWithReExecute("/error/{0}");
  
  [Route("[controller]")]
  public class ErrorController : Controller
  {
      [HttpGet("{statusCode}")]
      public IActionResult Error(int statusCode)
      {
          this.Response.StatusCode = statusCode;
          return this.View(statusCode);
      }
  }
  </code></pre>
  
  <p>However, visiting <code>/this-page-does-not-exist</code> results in a generic IIS 404 Not Found error page.</p>
  
  <p>Is there a way to handle requests that do not match any routes? How can I handle this type of request before IIS takes over? Ideally I would like to forward the request to <code>/error/404</code> so that my error controller can handle it.</p>
  
  <p>In ASP.NET 4.6 MVC 5, we had to use the httpErrors section in the Web.config file to do this.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;system.webServer&gt;
      &lt;httpErrors errorMode="Custom" existingResponse="Replace"&gt;
        &lt;remove statusCode="404" /&gt;
        &lt;error statusCode="404" responseMode="ExecuteURL" path="/error/404/" /&gt;
      &lt;/httpErrors&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>