Cache-control: no-store, must-revalidate not sent to client browser in IIS7 + ASP.NET MVC

Through trial and error, I have found that one way to set the headers correctly for IIS7 in ASP.NET MVC is:

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.AppendCacheExtension("no-store, must-revalidate");
Response.AppendHeader("Pragma", "no-cache");
Response.AppendHeader("Expires", "0");

The first line sets Cache-control to no-cache, and the second line adds the other attributes no-store, must-revalidate.

This may not be the only way, but does provide an alternative method if the more straightforward Response.AppendHeader("Cache-control", "no-cache, no-store, must-revalidate"); fails.

Other related IIS7 cache-control questions that may be solved by this are:

  • Something is forcing responses to have cache-control: private in IIS7
  • IIS7: Cache Setting Not Working... why?
  • IIS7 + ASP.NET MVC Client Caching Headers Not Working
  • Set cache-control for aspx pages
  • Cache-control: no-store, must-revalidate not sent to client browser in IIS7 + ASP.NET MVC