Tuesday, March 08, 2005

Disable browser caching in ASP.NET

You know how annoying might be when you hit the back button in your browser and the ASP.NET web page displays a cached result instead of refreshing itself. There is a way to force the browser not to cache an ASP.NET web page and you need to add only 1 line of code to your ASP.NET web pages in order to disable browser caching.

Add the following line on top of the Page_Load event handler and your ASP.NET page will not be cached in the users browsers:

Response.Cache.SetCacheability(HttpCacheability.NoCache);