views:

99

answers:

2

I have a view that shows a list of items and when you click on one of them it will take you to the items page. I also store a "Viewed" flag in the database for that item.

Now, when the user clicks back, the item should be styled differently because of the change in the "Viewed" flag. However, every time I click back, it is as it was before I clicked into the item, and I have to click refresh to see the actual state of the page now.

How can I prevent this page from being cached so when a user clicks back they will see the latest version of this site, complete with the new styling?

+2  A: 

Call this in your controller action:

Response.Cache.SetCacheability(HttpCacheability.NoCache)

This will prevent the browser from caching the page.

Eilon
+3  A: 

Mark the controller action that generates the list with the OutputCacheAttribute and set the cache location to none to prevent that page from being cached on the client. This should cause the client to request the page again. If the user is using the back button, however, I think that the page is served up by the browser without reloading regardless of the caching. At least in FF I don't see it requesting the page again using Firebug.

[OutputCache( Location = OutputCacheLocation.None )]
tvanfosson
If it isn't cached by the browser how could it serve it up again without reloading?
Max Schmeling
I originally thought it would reload, too, but that's not what I'm seeing in FF.
tvanfosson