【发布时间】:2015-05-06 08:26:40
【问题描述】:
我在新的 ASP.NET MVC 应用程序的自定义错误页面管理方面遇到了一个非常有趣的问题。
这个问题是这样的:
- 如果我在 URL 末尾调用带有“错误”参数的 URL(不管是哪个),例如 ..../c<,则应用程序将按照 web.config 中的说明显示正确的服务器错误页面;
- 如果我将 URL 更改为更讨厌的 URL,例如 .../<c(看起来更像一个 HTML 标记,浏览器中不再显示服务器错误页面,而是得到一个普通的 YSOD像An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.这样的消息
根据 ELMAH,两个请求都以 400 状态码结束,消息是:
- 第一个:System.Web.HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (<).
at System.Web.HttpRequest.ValidateInputIfRequiredByConfig()
at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context)
- 第二个:System.Web.HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (<).
at System.Web.HttpRequest.ValidateInputIfRequiredByConfig()
at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context)
因此,两个错误相同,状态代码相同,但对于其中一个错误,自定义错误页面未显示。我还在调试模式下访问了 global.asax 并检查了 protected void Application_Error(object sender, EventArgs e) 中的 Server.GetLastError() 并再次发现两个错误是相同的,没有什么不同。
在 web.config 中,我的 <customErrors> 标签如下所示:
<customErrors mode="On" defaultRedirect="/ServerError.aspx" redirectMode="ResponseRewrite">
<error statusCode="500" redirect="/ServerError.aspx" />
<error statusCode="404" redirect="/PageNotFound.aspx" />
</customErrors>
请有人告诉我为什么这两种情况下的行为不同?
非常感谢您的宝贵时间。
【问题讨论】:
-
您在什么平台上托管?卡西尼? IIS6? IIS7+?
-
IIS 8.5 (Windows 8.1) 和 Azure 网站。
标签: c# asp.net asp.net-mvc