Custom error page configured in IIS for code 400 (bad request) is ignored
Asked Answered
I

5

8

For my website I configured some custom error pages. If I generate a 404, the redirect works fine. When hitting a 400, the "bad request" text shows up instead of the configured URl.

As a test I copied the URL from 404 to 400. No change. Then I changed the redirect to a file. No change.

Any ideas?

Indus answered 6/11, 2008 at 12:56 Comment(1)
For any future readers of this discussion. You need to first determine what module of Windows/IIS gives you the 400 error page. Had it been http.sys (caused by factors such as oversize headers) or your web framework (caused by SOAP/REST errors), the way to customize that error page is closed or opened. Without this in mind, you wouldn't understand why some 400 can be customized and others not.Humbert
X
6

Maybe this is your answer: this Microsoft site says re configuring custom errors in IIS6 that

The following errors are not customizable: 400, 403.9, 411, 414, 500, 500.11, 500.14, 500.15, 501, 503, and 505.

Xenia answered 6/11, 2008 at 13:54 Comment(2)
Thanks for the answer. Although it's a good answer, it defenatly is not a sollution :(Indus
as of 03/07/2019 statusCode Required integer attribute. Specifies the number of the HTTP status code for which you want to create a custom error message. Acceptable values are from 400 through 999. learn.microsoft.com/en-us/previous-versions/iis/settings-schema/…Unhesitating
G
7

I've run in to the same problem, and found this on msdn http://msdn.microsoft.com/en-us/library/ms690497.aspx

I'm not sure if this will work on IIS6, but it certainly works on IIS7. You need to configure httpErrors, not the custom errors

<system.webServer>
      <httpErrors errorMode="Custom">
            <error statusCode="400" subStatusCode="-1" path="_path" responseMode="Redirect" />
      </httpErrors>
</system.webServer>
Gravitation answered 24/3, 2010 at 8:6 Comment(0)
X
6

Maybe this is your answer: this Microsoft site says re configuring custom errors in IIS6 that

The following errors are not customizable: 400, 403.9, 411, 414, 500, 500.11, 500.14, 500.15, 501, 503, and 505.

Xenia answered 6/11, 2008 at 13:54 Comment(2)
Thanks for the answer. Although it's a good answer, it defenatly is not a sollution :(Indus
as of 03/07/2019 statusCode Required integer attribute. Specifies the number of the HTTP status code for which you want to create a custom error message. Acceptable values are from 400 through 999. learn.microsoft.com/en-us/previous-versions/iis/settings-schema/…Unhesitating
H
3

Try

Response.TrySkipIisCustomErrors = true;

OR

<configuration>
  <system.webServer>
    <httpErrors existingResponse="PassThrough" />
  </system.webServer>
</configuration>

original post

Hazardous answered 2/10, 2012 at 8:55 Comment(0)
U
2

In 2020 it will work just like that web.config:

<system.webServer>
    <httpErrors errorMode="Custom" existingResponse="Replace">
      <remove statusCode="400" subStatusCode="-1" />
      ...
      <error statusCode="400" prefixLanguageFilePath="YOUR_PATH" path="YOUR_HTML_FILE" responseMode="File" />
    ...

statusCode

Required integer attribute.

Specifies the number of the HTTP status code for which you want to create a custom error message. Acceptable values are from 400 through 999.

https://learn.microsoft.com/en-us/previous-versions/iis/settings-schema/ms689487(v=vs.90)

Note that bad URL like https://stackoverflow.com/% still won't be customizable and one will get the simple Bad Request message coming from the IIS Kernel (Error Code 400).

More on that here https://serverfault.com/questions/257680/properly-handle-iis-request-with-percent-sign-in-url

Unhesitating answered 19/11, 2020 at 16:1 Comment(1)
There is usually nothing called "IIS Kernel". People commonly say http.sys or Windows HTTP API/service.Humbert
X
0

Check what's in your web.config file in the customErrors section. That has a defaultRedirect attribute, and an error subtag with a redirect attribute. These can conflict with your other configuration settings in IIS.

Xenia answered 6/11, 2008 at 13:31 Comment(1)
I have configured it the same as in IIS. Nevertheless, if the page would be incorrect, I would get a 404 is it not?Indus

© 2022 - 2024 — McMap. All rights reserved.