Application calls Begin_Request for images, css and js ASP.NET MVC 3

1k views Asked by At

I have this MVC application where I declare the following routings:

routes.RouteExistingFiles = false;

routes.IgnoreRoute("Content/{*pathInfo}");
routes.IgnoreRoute("Scripts/{*pathInfo}");

routes.IgnoreRoute("{*alljs}", new { alljs = @".*\.js(/.*)?" });
routes.IgnoreRoute("{*allcss}", new { allcss = @".*\.css(/.*)?" });

I deployed my application on IIS and I see that the Application_BeginRequest is called also for every static resource

protected void Application_BeginRequest(object sender, EventArgs e)
{
    Log.Write("Begin request for " + Request.RawUrl)
}

I tried to set the web.Config in this way:

<system.webServer>
  <validation validateIntegratedModeConfiguration="false" />
  <modules runAllManagedModulesForAllRequests="true" />
      <handlers accessPolicy="Read, Execute, Script">
          <add name="StaticFiles" path="*.js, *.css, *.jpg, *.jpeg, *.gif, *.png" verb="*" type="StaticFileModule" resourceType="Either" requireAccess="None" preCondition="integratedMode" />
      </handlers>
</system.webServer>

No success, unfortunately. Anyone has a clue for this?

1

There are 1 answers

2
SLaks On BEST ANSWER

Application_BeginRequest has nothing to do with routing.
It will always fire for all managed requests.

If you only want to handle MVC requests, use a global action filter.