Search code examples
asp.net-mvciiserror-handlingasp.net-corecustom-error-pages

404.20 Exception not being caught by ASP.net Core


I have created a new ASP.net 5 MVC6 project and added the following:

app.UseStatusCodePages();

inside my configure method. If I run the application, open my web browser and navigate to the following URL:

http://localhost:34741/invalidroute 

I am presented with a: Status Code: 404; Not Found error. This is expected, however if I make the route more complicated for example:

 http://localhost:34741/this/is/a/complicated/route/this/is/a/complicated/route/this/is/a/complicated/route/this/is/a/complicated/route/this/is/a/complicated/route/this/is/a/complicated/route/this/is/a/complicated/route/

I am presented with a HTTP Error 404.20 - Not Found IIS Detailed Error page. Why is this no longer being handled by asp?

I have tried playing around with httpErrors in my web.config file and I have also tried setting a default document in IIS but I can't get a custom error page working :(


Solution

  • https://support.microsoft.com/en-us/kb/943891

    404.20 comes from IIS. There is a setting "maxurlSegments" to control how many segments are allowed, which you can find in

    https://www.iis.net/configreference/system.applicationhost/sites/site/limits

    Modify that IIS setting and the error should go away.