我有这段代码来处理我的global.asax.cs文件中的HttpRequestValidationException.
protected void Application_Error(object sender, EventArgs e)
{
var context = HttpContext.Current;
var exception = context.Server.GetLastError();
if (exception is HttpRequestValidationException)
{
Response.Clear();
Response.StatusCode = 200;
Response.Write(@"<html><head></head><body>hello</body></html>");
Response.End();
return;
}
}
Run Code Online (Sandbox Code Playgroud)
如果我调试我的webapplication,它的工作完美.但是,当我把它放在我们的生产服务器上时,服务器忽略它并生成" 从客户端检测到一个有潜在危险的request.form值 " - 错误页面.我不知道究竟发生了什么......如果有人知道问题是什么,或者我做错了什么......?
另外,我不想在web.config中将validaterequest设置为false.
服务器使用IIS7.5,我使用的是asp.net 3.5.
谢谢,布鲁诺
我对新的ASP.NET MVC应用程序的自定义错误页面管理有一个非常有趣的问题.
这个问题是这样的:
- 如果我在URL的末尾用一个"坏"参数调用一个URL(无关紧要)..../c<,那么应用程序就会按照Web中的说明显示正确的服务器错误页面.配置;
- 如果我将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并检查了Server.GetLastError() …