我只想处理动作,但看起来Application_BeginRequest
也像方法句柄CSS
,图像等......
如何避免呢?
因为听起来我不能只为操作覆盖内容:
HttpContext.Current.RewritePath("~/Maintenance.html");
我只想处理动作,但看起来Application_BeginRequest
也像方法句柄CSS
,图像等......
如何避免呢?
因为听起来我不能只为操作覆盖内容:
HttpContext.Current.RewritePath("~/Maintenance.html");
如果您想限制仅对 Web 表单请求执行某项操作,我使用了如下内容:
protected void Application_BeginRequest(object sender, System.EventArgs e)
{
if(HttpContext.Current.Request.CurrentExecutionFilePathExtension == ".aspx"){
//stuff to do
}
}
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
}
}
尽管可能有另一种方法可以完全实现您的目标(您的问题并不清楚)。