Question

Will the code below work if the clock on the server is ahead of the clock on the client?

Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1))

EDIT: the reason I ask is on one of our web apps some users are claiming they are seeing the pages ( account numbers, etc ) from a user that previously used that machine. Yet we use the line above and others to 'prevent' this from happening.

Was it helpful?

Solution

This question covers making sure a webpage is not cached. It seems you have to set several properties to ensure a web page is not cached across all browsers.

OTHER TIPS

Your problem could be caused by the browser remembering data entered into form fields. You can turn this off like this:

<input autocomplete="off">

As far as I can tell, the browser will check the expiry date against the local clock (although it will account for the time zone), so the code in your question may not work as you expect if the client's clock is inaccurate. Most commonly, this happens when their time looks right but is set to the wrong timezone, meaning the UTC timestamps are actually out by several hours.

You could try setting a much older timestamp, say: 0000 1st Jan 1970 GMT (epoch)

I think the code you have should work with the server side caching, but you can more explicitly disable it with:

Response.Cache.SetNoServerCaching();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top