【问题标题】:Force "page is expired" message instead of refreshing page from server when using the Back button使用“后退”按钮时,强制“页面已过期”消息而不是从服务器刷新页面
【发布时间】:2012-07-04 02:54:45
【问题描述】:

我创建了一个包含两个页面的简单 ASP.NET 3.5 Web 应用程序。每个页面都有一个显示时间的标签和一个回发按钮。在每个页面的 Page_Load 中,我有以下内容:

        Response.ClearHeaders();
        Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1 
        Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1 
        Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1 
        Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1 
        Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1  
        Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1  
        Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1  
        Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1  
        Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1  
        Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1 

如果用户单击“返回”按钮,我想强制显示“页面已过期”消息。但是,正在发生的事情是“后退”按钮显示上一页,而不是从缓存中提取,而是刷新页面。标签将更新为当前时间。我不希望页面刷新,而是显示“页面已过期”消息。我怎么能强迫它?我已经使用 IE9 对此进行了测试,但我需要所有浏览器的行为都相同。

【问题讨论】:

标签: asp.net caching browser-cache


【解决方案1】:

“页面已过期”消息通常在浏览器向页面发送 POST 请求并且用户希望刷新或返回该页面时给出。要强制它,您必须使每个页面都成为 POST 请求。 This thread 或许能够为您提供 JavaScript 代码,以将所有链接(即 GET 请求)转换为 POST 请求。

或者,您可以使用 JavaScript 或 cookie 来保存访问过的页面的历史记录,如果用户尝试返回某个页面,您可以使用它来重定向他们或给他们一条消息。

【讨论】:

    猜你喜欢
    • 2012-03-02
    • 1970-01-01
    • 1970-01-01
    • 2021-04-28
    • 2010-12-26
    • 2011-02-13
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    相关资源
    最近更新 更多