2

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).

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Cacho Santa
  • 6,846
  • 6
  • 41
  • 73

2 Answers2

2

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).

Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

See my answer to Custom error page configured in IIS for code 400 (bad request) is ignored

in short the redirect with <httpErrors errorMode="Custom" ... works already also for HTTP 400 / bad request and one can customize it except for the errors blocked by the IIS Kernel (for example bad URL)

I am not sure about the version of IIS where it started working. I tested it on IIS 10.

The example https://stackoverflow.com/% still won't work, but

return new HttpStatusCodeResult(HttpStatusCode.BadRequest); will work as expected (it won't be blocked from the IIS Kernel)

Alexander Mihailov
  • 1,050
  • 1
  • 12
  • 19