I am looking for a method to disable the browser cache for an entire ASP.NET MVC Website
I found the following method:
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.Cache.SetNoStore();
And also a meta tag method (it won't work for me, since some MVC actions send partial HTML/JSON through Ajax, without a head, meta tag).
<meta http-equiv="PRAGMA" content="NO-CACHE">
But I am looking for a simple method to disable the browser cache for an entire website.
I implemented all the previous answers and still had one view that did not work correctly.
It turned out the name of the view I was having the problem with was named 'Recent'. Apparently this confused the Internet Explorer browser.
After I changed the view name (in the controller) to a different name (I chose to 'Recent5'), the solutions above started to work.
Instead of rolling your own, simply use what's provided for you.
As mentioned previously, do not disable caching for everything. For instance, jQuery scripts used heavily in ASP.NET MVC should be cached. Actually ideally you should be using a CDN for those anyway, but my point is some content should be cached.
What I find works best here rather than sprinkling the [OutputCache] everywhere is to use a class:
All of your controllers you want to disable caching for then inherit from this controller.
If you need to override the defaults in the NoCacheController class, simply specify the cache settings on your action method and the settings on your Action method will take precedence.
Create a class that inherits from IActionFilter.
Then put attributes where needed...
UI
Background
You can try below code in Global.asax file.
I know this answer is not 100% related to the question, but it might help someone.
If you want to disable the browser cache for the entire ASP.NET MVC Website, but you only want to do this TEMPORARILY, then it is better to disable the cache in your browser.