title: How to programmatically disable OutputCache on application start in ASP.NET MVC
body: <p>I would like the <code>OutputCache</code> feature to be disabled if the <code>system.web.compilation</code> setting in the web.config is set to <code>debug="true"</code>.</p>
  
  <p>I can successfully access this value by calling this method in my Global.asax's <code>Application_Start()</code>:</p>
  
  <pre><code>public static void RegisterGlobalFilters(GlobalFilterCollection filters)
  {
      filters.Add(new HandleErrorAttribute());
      CompilationSection configSection = (CompilationSection)ConfigurationManager.GetSection("system.web/compilation");
      if (configSection?.Debug == true)
      {
          filters.Add(new OutputCacheAttribute()
          {
              VaryByParam = "*",
              Duration = 0,
              NoStore = true
          });
      }
  }
  </code></pre>
  
  <p>The problem is, any endpoints in my controllers that have <code>OutputCache</code> explicitly set will not use the global filter that was set up.</p>
  
  <pre><code>[OutputCache(CacheProfile = "Month")]
  [HttpGet]
  public ViewResult contact()
  {
      return View();
  }
  </code></pre>
  
  <p>Here is where that "Month" profile is defined in my web.config:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;system.web&gt;
    &lt;caching&gt;
      &lt;outputCacheSettings&gt;
        &lt;outputCacheProfiles&gt;
          &lt;add name="Month" duration="2592000" location="Any" varyByParam="*" /&gt;
        &lt;/outputCacheProfiles&gt;
      &lt;/outputCacheSettings&gt;
    &lt;/caching&gt;
  &lt;/system.web&gt;
  </code></pre>
  
  <p>I need to be able to nullify the use of explicitly defined OutputCache profiles, like "Month", when I'm in debugging mode. How can I do this?</p>