Reputation: 8091
I want to handle only for actions but looks like Application_BeginRequest
method handles also CSS
, images etc...
How to avoid it ?
Because sounds like I can't override content only for actions:
HttpContext.Current.RewritePath("~/Maintenance.html");
Upvotes: 1
Views: 2009
Reputation: 15797
The HttpApplication.BeginRequest Event "occurs as the first event in the HTTP pipeline chain of execution when ASP.NET responds to a request."
So any request going through your ASP.NET pipeline will trigger this, not just *.aspx, etc.
You can't avoid it, but you can check the path of the requested file and perform and action as needed, like:
protected void Application_BeginRequest(object sender, System.EventArgs e)
{
string file = Request.Url.LocalPath.ToLower();
if (file == ("/user/singin"))
{
//something
}
}
Though there may be another way altogether to accomplish your goal (which isn't clear from your question).
Upvotes: 1
Reputation: 7141
If you want to restrict doing something only to web forms requests, I've used something like the following:
protected void Application_BeginRequest(object sender, System.EventArgs e)
{
if(HttpContext.Current.Request.CurrentExecutionFilePathExtension == ".aspx"){
//stuff to do
}
}
Upvotes: 3