How to refresh page when hitting back button on br

2019-06-21 05:27发布

问题:

Most browsers reload the page from cache and do not perform a round trip server refresh. I added Response.AppendHeader("Cache-Control", "no-store") on Page_Load but not working for Chrome, Firefox, Safari. How to refresh page when hitting back button on browser (IE,Chrome,Firefox Safari) ?

回答1:

This would be for your c# code I'm assuming. These are my suggestions in order of most suggested to least.

Response.Cache.SetNoStore();

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.AppendHeader("pragma","no-cache");

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


回答2:

It's probably a bad idea to force this behavior because the user is expecting to see what they saw before, not a refreshed view. If that's the behavior of Chrome/Firefox/Safari then presumably the users desire this behavior because they chose that browser. If they want a refreshed view, they can refresh on their own.

That said, I often see this done with Javascript in the browser. You can hook into page load events and manually refresh if you see the page being loaded a second time. But if the client uses noscript, or otherwise doesn't support Javascript, then you're out of luck. Also, be careful to reload correctly so that users don't get taken to a new page every time they click Back and get stuck in a battle of fast-clicking reflexes.