What's the best way to deal with cache and the browser back button?

前端 未结 5 1711
心在旅途
心在旅途 2021-02-06 03:24

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

5条回答
  •  长情又很酷
    2021-02-06 04:02

    The following code worked for me in IE9+, FF21 and Latest Chrome:

    Response.Cache.SetCacheability(HttpCacheability.NoCache | HttpCacheability.Private);
    Response.Cache.AppendCacheExtension("must-revalidate");
    Response.Cache.AppendCacheExtension("max-age=0");
    Response.Cache.SetNoStore();
    

    You can place this in Page_Load() event handler in the MasterPage so that every page in your app requires a round-trip to the server when pressing the back button.

提交回复
热议问题