Search code examples
iiserror-handlingasp.net-mvc-5iis-8

Customize error 400 (Bad Request) avoid IIS-8 intercepting it


The request is intercepted by the IIS, and it never hits my application.

I want that my Error Handling to manage this error, not IIS. Is this possible?

I've tried many things, including these:

  1. In my Web.config: <httpErrors errorMode="DetailedLocalOnly" existingResponse="PassThrough"></httpErrors>

  2. Also this configuration:

<httpErrors errorMode="DetailedLocalOnly" existingResponse="PassThrough">
    <remove statusCode="400"/>
    <error statusCode="400" path="http://www.google.com" responseMode="Redirect"/>
</httpErrors>
  1. From the MSDN (IIS 7, nothing on IIS 8 documentation):

You cannot customize the following HTTP error messages: 400, 403.9, 411, 414, 500, 500.11, 500.14, 500.15, 501, 503, and 505.

Here we can replicate the error:

https://stackoverflow.com/ + %%% (you should copy the entire link, with the invalid characters included).


Solution

  • It seems that you are out of luck with this as the following thread already shows: https://serverfault.com/questions/257680/properly-handle-iis-request-with-percent-sign-in-url

    One possible solution is to handle this error code at your load balancer (which of course will not be IIS based).