gpt4 book ai didi

c# - IIS 将自定义错误页面作为纯文本提供,没有内容类型 header

转载 作者:可可西里 更新时间:2023-11-01 08:03:49 25 4
gpt4 key购买 nike

UPD:这是 full solution for error handling

我有普通的 vanilla MVC4 网络项目。没有添加任何内容,也没有删除任何内容,只是在 Visual Studio 中创建了一个新项目。

web.config 中,我添加了自定义错误页面处理程序:

<customErrors mode="On" defaultRedirect="~/Content/Error.htm" redirectMode="ResponseRewrite" />

~/Content/Error.htm 文件是:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>OOPS! Error Occurred. Sorry about this.</title>
</head>
<body>
<h2>OOPS! Error Occurred</h2>
</body>
</html>

每当我在网站上遇到 404 错误时,Error.htm 在 Firefox 和 Chrome 中作为明文提供:

HTML is displayed as plain text

Fiddler 表示错误页面在没有 content-type header 的情况下提供,这导致浏览器将页面呈现为纯文本:

No Content-type header

有没有办法强制使用 content-type header 的 IIS 服务器错误页面?

附注实际问题出在一个复杂的 MVC4 项目中,它在 Global.asax 中有自己的错误处理。但我发现有些错误不会通过 ASP 管道,而只能由 IIS 处理。喜欢dot at the end of the url .解决方案 < httpErrors />确实提供正确的响应,但我们在 Global.asax 中的自定义错误处理,Application_Error() 没有以这种方式被调用。

UPD 看来我赢不了这场 war 了。 IE 显示正确呈现的 html,Firefox 和 Chrome 显示为纯文本。当我切换到纯文本时,Firefox 和 IE 正确显示空白,IE 吞下空白并尝试呈现 html。如果我尝试将图像作为错误页面提供,Firefox 和 Chrome 会显示图像。 IE显示这个: IE9 is on crack!打脸!

最佳答案

错误页面使用 .aspx 而不是 .htm(将 htm 重命名为 aspx)。

<customErrors mode="On" defaultRedirect="~/Content/Error.aspx" redirectMode="ResponseRewrite" />

关于c# - IIS 将自定义错误页面作为纯文本提供,没有内容类型 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15384148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com