我正在处理一个新的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)
因此,两个错误都相同,状态码也相同,但对于其中一个错误,自定义错误页面不再显示。我还在全局.asax文件中以调试模式检查了protected void Application_Error(object sender, EventArgs e)
中的Server.GetLastError()
,结果两个错误都是一样的,没有什么不同。
在web.config中,我的<customErrors>
标记如下所示:
<customErrors mode="On" defaultRedirect="/ServerError.aspx" redirectMode="ResponseRewrite">
请问为什么这两种情况的行为不同?
非常感谢您的时间。