我试图重写Web窗体的onError事件处理程序,以允许“从客户端检测到潜在危险的Request.Form值”类型错误要在窗体内处理而不是结束在应用程序级错误处理程序。处理请求验证'默默'
我发现一些示例代码是这样的:
protected override void OnError(EventArgs e)
{
// At this point we have information about the error
HttpContext ctx = HttpContext.Current;
Exception exception = ctx.Server.GetLastError();
string errorInfo =
"<br>Offending URL: " + ctx.Request.Url.ToString() +
"<br>Source: " + exception.Source +
"<br>Message: " + exception.Message +
"<br>Stack trace: " + exception.StackTrace;
ctx.Response.Write(errorInfo);
// --------------------------------------------------
// To let the page finish running we clear the error
// --------------------------------------------------
ctx.Server.ClearError();
base.OnError(e);
}
令人满意地捕获错误并进行写入一条错误消息的屏幕,但我真正想要做的是要意识到错误时的Page_Load火灾所以能够在webform上显示'正常'错误消息。
我敢肯定有一个很好的方法来做到这一点,但我不知道它!建议?
(BTW各种原因,我不希望检查在任一形式或应用程序级别关闭,我也不希望依赖于JavaScript - 感谢)