title: Default Anti forgery disabling Response Caching in ASP.NET Core 2.0
body: <p>I'm trying to implement response caching and disabling default anti forgery behaviour on certain actions, but on every request I get "</p>
  
  <blockquote>
    <p>warn: Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgery[8]
    The 'Cache-Control' and 'Pragma' headers have been overridden and set
    to 'no-cache, no-store' and 'no-cache' respectively to prevent caching
    of this response. Any response that uses antiforgery should not be
    cached.</p>
  </blockquote>
  
  <p>I define <em>IgnoreAntiforgeryToken</em> on the action. Is there another way to turn off the default anti forgery?</p>
  
  <p><strong>Startup.cs</strong>:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      .
      .
      .
      services.AddResponseCaching();
  
      services.AddMvc(options =&gt;
              {
                  options.CacheProfiles.Add("Default",
                      new CacheProfile()
                      {
                          Duration = 240
                      });
                  options.CacheProfiles.Add("NoCache",
                      new CacheProfile()
                      {
                          Location = ResponseCacheLocation.None,
                          NoStore = true
                      });
              })
              .AddViewLocalization(Microsoft.AspNetCore.Mvc.Razor.LanguageViewLocationExpanderFormat.Suffix)
              .AddDataAnnotationsLocalization();
  }
  
  public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  {
      .
      .
      .
      app.UseResponseCaching();
  }
  </code></pre>
  
  <p><strong>Controller.cs</strong>:</p>
  
  <pre><code>[IgnoreAntiforgeryToken]
  [ResponseCache(CacheProfileName = "Default", VaryByQueryKeys = new string[] { "id" })]
  [HttpGet("/Shop/Category/{id:int}", Name = "Category")]
  public IActionResult Category(int id)
  {
      var result = this.AppHelper.ModelHelper.GetCategoryWrap(id);
  
      return View(result);
  }
  </code></pre>