1

我只想处理动作,但看起来Application_BeginRequest也像方法句柄CSS,图像等......

如何避免呢?

因为听起来我不能只为操作覆盖内容:

HttpContext.Current.RewritePath("~/Maintenance.html");
4

2 回答 2

3

如果您想限制仅对 Web 表单请求执行某项操作,我使用了如下内容:

protected void Application_BeginRequest(object sender, System.EventArgs e)
{
    if(HttpContext.Current.Request.CurrentExecutionFilePathExtension == ".aspx"){
         //stuff to do
    }
}
于 2013-10-10T17:22:17.623 回答
1

HttpApplication.BeginRequest 事件“在 ASP.NET 响应请求时作为 HTTP 执行管道链中的第一个事件发生。”

所以通过你的 ASP.NET 管道的任何请求都会触发这个,而不仅仅是 *.aspx 等。

您无法避免,但您可以检查请求文件的路径并根据需要执行和操作,例如:

protected void Application_BeginRequest(object sender, System.EventArgs e)
{
    string file = Request.Url.LocalPath.ToLower();
    if (file == ("/user/singin"))
    {
        //something
    }
}

尽管可能有另一种方法可以完全实现您的目标(您的问题并不清楚)。

于 2013-10-10T16:58:10.897 回答