<p>What's the best way to handle a user going back to a page that had cached items in an asp.net app?  Is there a good way to capture the back button (event?) and handle the cache that way?</p>

[{'answer_id': 23104, 'author': 'TheSmurf', 'author_id': 1975282, 'author_profile': 'https://Stackoverflow.com/users/1975282', 'pm_score': 0, 'selected': False, 'text': "<p>The best way to deal with it is to probably put a no-cache directive in your ASP.NET pages (or a master page if you're using one). I don't think there's a way to deal with this directly in your ASP.NET code (since the cache decision is happening on the client).</p>\n\n<p>As for MVC, don't know how you would accomplish that (assuming it's different from Web Forms-based ASP.NET); I haven't used it.</p>\n"}, {'answer_id': 23108, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 3, 'selected': False, 'text': '<p>As far as I know (or at least have read) is its best to try not to work in response to user events, but rather think "in the page"..</p>\n\n<p>Architect your application so it doesn\'t care if the back button is pushed.. It will just deal with it.. This may mean a little extra work from a development point of view, but overall will make the application a lot more robust..</p>\n\n<p>I.e if step 3 performs some data chages, then the user clicks back (to step 2) and clicks next again, then the application checks to see if the changes have been made.. Or ideally, it doesnt make any <em>hard</em> changes until the user clicks "OK" at the end.. This way, all the changes are stored and you can repopulate the form based on previously entered values on load, each and every time..</p>\n\n<p>I hope that makes sense :)</p>\n'}, {'answer_id': 24334, 'author': 'travis', 'author_id': 1414, 'author_profile': 'https://Stackoverflow.com/users/1414', 'pm_score': 4, 'selected': True, 'text': '<p>You can try using the <a href="http://msdn.microsoft.com/en-us/library/system.web.httpresponse.cache.aspx" rel="noreferrer">HttpResponse.Cache property</a> if that would help:</p>\n\n<pre><code>Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));\nResponse.Cache.SetCacheability(HttpCacheability.Public);\nResponse.Cache.SetValidUntilExpires(false);\nResponse.Cache.VaryByParams["Category"] = true;\n\nif (Response.Cache.VaryByParams["Category"])\n{\n   //...\n}\n</code></pre>\n\n<p>Or could could block caching of the page altogether with <a href="http://msdn.microsoft.com/en-us/library/system.web.httpresponse.cachecontrol.aspx" rel="noreferrer">HttpResponse.CacheControl</a>, but its been deprecated in favor of the Cache property above:</p>\n\n<pre><code>Response.CacheControl = "No-Cache";\n</code></pre>\n\n<p>Edit: OR you could really <a href="http://forums.asp.net/t/1013531.aspx" rel="noreferrer">go nuts</a> and do it all by hand:</p>\n\n<pre><code>Response.ClearHeaders();\nResponse.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1\nResponse.AppendHeader("Cache-Control", "private"); // HTTP 1.1\nResponse.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1\nResponse.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1\nResponse.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1 \nResponse.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1 \nResponse.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1 \nResponse.AppendHeader("Pragma", "no-cache"); // HTTP 1.1 \nResponse.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1 \nResponse.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1 \n</code></pre>\n'}, {'answer_id': 217096, 'author': 'Kornel', 'author_id': 27009, 'author_profile': 'https://Stackoverflow.com/users/27009', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.13" rel="nofollow noreferrer">RFC 2616 §13.13</a> says that <strong>History and Cache are different things</strong>. There should be absolutely no way for cache to affect Back button.</p>\n\n<p>If any combination of HTTP headers affects Back button, it\'s a bug in the browser …with one exception.</p>\n\n<p>In HTTP<b>S</b> browsers interpret <code>Cache-control: must-revalidate</code> as request to refresh pages when Back button is used (Mozilla calls it "silly bank mode"). This isn\'t supported in plain HTTP.</p>\n'}, {'answer_id': 28466691, 'author': 'Steven de Salas', 'author_id': 448568, 'author_profile': 'https://Stackoverflow.com/users/448568', 'pm_score': 0, 'selected': False, 'text': '<p>The following code worked for me in IE9+, FF21 and Latest Chrome:</p>\n\n<pre><code>Response.Cache.SetCacheability(HttpCacheability.NoCache | HttpCacheability.Private);\nResponse.Cache.AppendCacheExtension("must-revalidate");\nResponse.Cache.AppendCacheExtension("max-age=0");\nResponse.Cache.SetNoStore();\n</code></pre>\n\n<p>You can place this in <code>Page_Load()</code> event handler in the MasterPage so that every page in your app requires a round-trip to the server when pressing the back button.</p>\n'}]
['https://Stackoverflow.com/questions/23094', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1874/']