0

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?

Michał Powaga
  • 22,561
  • 8
  • 51
  • 62
ab_732
  • 3,639
  • 6
  • 45
  • 61

1 Answers1

1

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.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • You are saying: do not use Begin_Request but use global action filter instead? – ab_732 Nov 21 '11 at 21:11
  • Yes. Or, better yet, instantiate it lazily when first used. Or use a non-global filter and apply that filter to each action that needs the DB. – SLaks Nov 21 '11 at 21:31