views:

708

answers:

4

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.

+2  A: 

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.

Dave Webb
A: 

@Dave

Yes I understand that and we do follow all that I was just wondering if the scenario could happen.

    Response.Cache.SetNoStore()
    Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache)
    Response.AddHeader("Pragma", "No-Cache") 'Tell proxy servers not to cache the page.
    Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1))
osp70
What if the user you are working with has been hitting the back button? I've seen it on a number of apps that the browser doesn't do a roundtrip to the server and just pulls everything from the cache (even some online banking institutions in the uk do it). Could it be a red herring?
Mauro
A: 

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

<input autocomplete="off">
Joseph Bui
The accounts are loaded into a list box on server side. So not sure this is happening. Thanks though
osp70
A: 

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();
Andrew Johnson