joek1975
joek1975

Reputation: 3583

How can I ensure that the browser does not cache a page

I need to make sure that the page is reloaded when going back to a page, without showing any messages to the user.

This must behave the same across all browsers.

Upvotes: 2

Views: 352

Answers (2)

James Johnson
James Johnson

Reputation: 46067

Try this:

EDIT - Added SetNoStore()

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

I think you can do it this way too:

<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">

Here's a solution that's specific for Safari:

<body onunload="" ...>

Here's another solution, but it's a bit of a hack:

<script type="text/javascript">
function noBack(){window.history.forward();}
noBack();
window.onload=noBack;
window.onpageshow=function(evt){if(evt.persisted)noBack();}
window.onunload=function(){void(0);}
</script>

Upvotes: 0

rick schott
rick schott

Reputation: 21137

The only way I have been able to achieve this reliably, especially with AJAX, is to append a query-string token on the page Url, such as DateTime.Now.Ticks.

You cannot count on <META> tags.

http://bla.com/bla.aspx?token=348343889

Upvotes: 1

Related Questions