IIS 中为代码 400(错误请求)配置的自定义错误页面被忽略

发布于 2024-07-08 15:25:26 字数 175 浏览 3 评论 0原文

对于我的网站,我配置了一些自定义错误页面。 如果我生成 404,则重定向工作正常。 当点击 400 时,会显示“错误请求”文本,而不是配置的 URl。

作为测试,我将 URL 从 404 复制到 400。没有任何变化。 然后我将重定向更改为文件。 不用找了。

有任何想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

冷情 2024-07-15 15:25:26

我也遇到了同样的问题,在msdn上找到了这个
http://msdn.microsoft.com/en-us/library/ms690497.aspx

我不确定这是否适用于 IIS6,但它肯定适用于 IIS7。
您需要配置httpErrors,而不是自定义错误

<system.webServer>
      <httpErrors errorMode="Custom">
            <error statusCode="400" subStatusCode="-1" path="_path" responseMode="Redirect" />
      </httpErrors>
</system.webServer>

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>
待"谢繁草 2024-07-15 15:25:26

也许就是您的答案:此 Microsoft 站点表示在 IIS6 中重新配置自定义错误

以下错误不是
可定制:400、403.9、411、414、
500、500.11、500.14、500.15、501、503、
和505。

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.

最好是你 2024-07-15 15:25:26

尝试

Response.TrySkipIisCustomErrors = true;

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

原始帖子

Try

Response.TrySkipIisCustomErrors = true;

OR

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

original post

情绪少女 2024-07-15 15:25:26

到 2020 年,它将像 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" />
    ...

状态代码

必需的整数属性。

指定要为其创建自定义错误消息的 HTTP 状态代码的编号。 可接受的值是从 400 到 999。

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

请注意,像 https://stackoverflow.com/% 仍然无法自定义,并且会收到来自 IIS 内核的简单错误请求消息(错误代码 400)。

更多相关内容请点击这里
https://serverfault.com/questions/257680/properly-处理 iis-request-with-percent-sign-in-url

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

紫罗兰の梦幻 2024-07-15 15:25:26

检查 web.config 文件中 customErrors 部分的内容。 它有一个 defaultRedirect 属性,以及一个带有 redirect 属性的 error 子标签。 这些可能与 IIS 中的其他配置设置冲突。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文