在引发"从客户端检测到潜在危险的 Request.Path 值"之前,ASP.NET 页面生命周期中是否存在任何位置



我希望能够在抛出 HttpException "从客户端检测到潜在危险的 Request.Path 值"之前对传入的请求进行一些检查。在 ASP.NET 生命周期中,我是否可以做到这一点?

这是在装有 IIS 8.5 的较旧 ASP.NET Web 窗体应用程序上。

  • 我知道为什么会发生异常,并且我不会试图通过ValidateRequest="false"或web.config设置来阻止它
  • 我不想抓住它,我知道我可以在global.asax中做到这一点Application_Error

我以为 HttpModules 是在处理请求之前运行的,但是当我尝试请求像"http://example.com/>"这样的 URL 时,向我的模块的Init()方法添加断点不会命中,所以错误甚至比这更早抛出。

如果有用,这里是完整的错误:

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 中尝试此事件。很久以前,我将该方法与注释一起添加到我的 Global.asax 页面,但从未真正使用它。我只是做了一个快速运行,将<script>添加到文本框控件并单击一个按钮,这个事件在页面轰炸之前被击中。

// This event is executed for every page request
// and is run before the PreInit event. Therefore we
// can use it to set the theme and master for every page.
protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
}

最新更新