【问题标题】:ERR_CACHE_MISS when navigating back to an ASPX page导航回 ASPX 页面时出现 ERR_CACHE_MISS
【发布时间】:2015-05-27 16:03:39
【问题描述】:

我有一个 WebForms 应用程序,其中第一页基本上是一个网格,其中包含指向加载 PDF 查看器的第二页的链接。网格实际上位于 .ascx 控件中。从第一页到 PDF 查看器页面,一切正常。但是,当我点击后退按钮返回第一页时。我收到以下错误(在 Chrome 中,但在其他浏览器中也会发生这种情况):

如果我点击后退按钮,浏览器会返回第一页,一切正常,但我需要解决这个错误。

我已经尝试根据this StackOverflow answer 的建议禁用第一页中的缓存,如下所示:

Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
Response.AppendHeader("Expires", "0"); // Proxies.

我也试过这个:

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Cache.SetExpires(DateTime.MinValue);

我已将此代码放在 .aspx 页面和 .ascx 控件(在 OnInit 方法中)后面的代码中,但均无济于事。我在这里错过了什么?

【问题讨论】:

  • 使用 pdf 查看器导航到页面的代码是什么?具体来说,您是否使用回发来进行导航?

标签: c# asp.net caching


【解决方案1】:

正如@JJS 暗示的那样,听起来您正在使用 OnClick(可能通过 LinkBut​​ton 或 ImageButton)导致部分/全部回发,并且您的重定向发生在代码隐藏中。如果这是正确的,您是否有理由不使用超链接?

缓存处理不是解决办法。浏览器表示页面之间发生了帖子。

【讨论】:

  • 我没有充分的理由不使用 HyperLink 控件。我切换到那些,现在它可以工作了。感谢您帮助我记住 LinkBut​​tons 和 HyperLinks 的不同用途!
【解决方案2】:

重写 OnPreInit 方法并在 Response 对象上设置各种缓存相关的属性,以防止浏览器缓存页面。

protected override void OnPreInit(EventArgs e)
{
    base.OnPreInit(e);

    Response.Buffer = true;
    Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
    Response.Expires = -1500;
    Response.CacheControl = "no-cache";
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
}

您可以执行类似的操作来禁用浏览器页面缓存,如下所示:

   Response.Cache.SetCacheability(HttpCacheability.NoCache);
   Response.Cache.SetExpires(Now.AddSeconds(-1));
   Response.Cache.SetNoStore();
   Response.AppendHeader("Pragma", "no-cache");

【讨论】:

    猜你喜欢
    • 2018-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多