user279521
user279521

Reputation: 4807

Issue with asp.net web pages being cached

I want to prevent my asp.net / c# 2008 web pages from being cached on the client side or the server side.

How can I go about doing that?

Upvotes: 4

Views: 2417

Answers (3)

Ahmed Adel
Ahmed Adel

Reputation: 11

The page is being cached, so the solution to not make it cached on the client side is to put this tag:

<%@ Outputcache Location="None"%>

before the page tag:

<%@ page >

The result looks like this:

<%@ OutputCache Location="None" %>

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

Upvotes: 1

Sky Sanders
Sky Sanders

Reputation: 37074

In your question, you specify no cache on both the client and server. To me this means no caching anywhere.

This will prevent any caching from happening anywhere.

Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

Either put this in the load of the page(s) you don't want cached or create a base page class.

from http://skysanders.net/subtext/archive/2010/03/23/preventing-caching-of-content-in-asp.net-pages-and-other-httphandlers.aspx

Upvotes: 0

kemiller2002
kemiller2002

Reputation: 115488

For the client side you want to use the No-Cache

http://www.i18nguy.com/markup/metatags.html

Here is a link describing how to configure the response object for no caching on the server side:

http://www.extremeexperts.com/Net/FAQ/DisablingBackButton.aspx

Response.Buffer = True  
Response.ExpiresAbsolute = Now().Subtract(New TimeSpan(1, 0, 0, 0)) 
Response.Expires = 0 
Response.CacheControl = "no-cache"

Upvotes: 3

Related Questions