代码之家  ›  专栏  ›  技术社区  ›  Brad Robinson

“上一步刷新页面”按钮需要什么HTTP头?

  •  0
  • Brad Robinson  · 技术社区  · 15 年前

    当从“后退”按钮导航到某个页面时,我正在尝试刷新该页面。根据我在阅读了一点后的理解,我应该只需要将页面标记为不可缓存,但是我不能让任何浏览器刷新页面。以下是我当前的邮件头:

    Cache-Control:no-cache
    Connection:keep-alive
    Content-Encoding:gzip
    Content-Length:1832
    Content-Type:text/html; charset=utf-8
    Date:Mon, 07 Jun 2010 14:05:39 GMT
    Expires:-1
    Pragma:no-cache
    Server:Microsoft-IIS/7.5
    Vary:Accept-Encoding
    Via:1.1 smoothwall:800 (squid/2.7.STABLE6)
    X-AspNet-Version:2.0.50727
    X-AspNetMvc-Version:2.0
    X-Cache:MISS from smoothwall
    X-Powered-By:ASP.NET
    

    为什么浏览器会将此页面从浏览器历史记录中拉出来而不刷新它?

    1 回复  |  直到 15 年前
        1
  •  0
  •   Brad Robinson    15 年前

    明白了。这就是我发现的工作:

    Cache-Control:no-cache, no-store
    Connection:Close
    Content-Length:7683
    Content-Type:text/html; charset=utf-8
    Date:Wed, 09 Jun 2010 03:37:38 GMT
    Expires:-1
    Pragma:no-cache
    Server:ASP.NET Development Server/9.0.0.0
    X-AspNet-Version:2.0.50727
    X-AspNetMvc-Version:2.0
    

    使用以下ASP.NET代码实现:

    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetAllowResponseInBrowserHistory(false);
    Response.Cache.SetMaxAge(new TimeSpan(0));
    Response.Cache.SetNoStore();
    Response.Cache.SetExpires(new DateTime(1940, 1, 1));