title: How to switch off caching for MVC requests but not for static files in IIS7?
body: <p>I'm developing an ASP.NET MVC application. Most of the controller actions are not supposed to be cached. Because of this I output no-cache headers in <code>Application_BeginRequest</code>:</p>
  
  <pre><code>    protected void Application_BeginRequest()
      {
          HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
          HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
          HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
          HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
          HttpContext.Current.Response.Cache.SetNoStore();
      }
  </code></pre>
  
  <p>The application is running on IIS7 with modules config setting <code>runAllManagedModulesForAllRequests="true"</code>. This means that all static files pass through the request pipeline as well (and get caching disabled).</p>
  
  <p>What is the best way to keep caching enabled for these static files? Do I have to check on extension before setting the response cache headers in <code>Application_BeginRequest</code> or is there an easier way (like bypassing the request pipeline for static files altogether)?</p>