Main FAQ Category: Caching (1)
How to disable Client Side and Proxy Caching of ASP.NET page?
Posted: 6-Apr-2008
Updated: 6-Apr-2008
Views: 25722

By using all the Server Side caching features of ASP.NET 2.0 we can make our WebSites much more responsive and serve larger number of web requests at the same time (without buying new hardware) .

But we must not forget that Caching happens on the client side also, when Web Browser stores pages in its internal cache on the users Hard Drive or when user is accessing the internet over some HTTP Proxy.

Sometimes this client side caching is very useful, for example for some statical content, like images.
It would be pointless if users browser would retrieve some static logo image each time a page is loaded.

On the other hand, sometimes we have some pages with critical data (Realtime reports etc) that we explicitly do not want to be cached on the client side (users Web Browser cache) or at some Web Proxy he might be using...

If we don't configure client side caching properly, it can happen that our users are looking at same stale data from their browser cache while there is new data on server.

Fortunately there is an easy way to disable client side caching in ASP.NET. To be precise we can do it in many ways.

To disable client side caching declaratively:

<%@ OutputCache Location="None" VaryByParam="None" %>


To disable client side caching programmatically:

    protected void Page_Load(object sender, EventArgs e)

    {

        Response.Cache.SetCacheability(HttpCacheability.NoCache);

    }


That was easy right?

You can find more info on Caching in ASP.NET in this useful MSDN article:  How to cache in ASP.NET by using Visual C# .NET