【问题标题】:Disable Back Button (showing cached version) without JavaScript在没有 JavaScript 的情况下禁用后退按钮(显示缓存版本)
【发布时间】:2010-05-29 14:13:16
【问题描述】:

我想在不使用 javascript 的情况下禁用浏览器后退按钮。到目前为止,我已经使用了这种编码:

Response.CacheControl = "no-cache"
Response.CacheControl = "private"
Response.CacheControl = "public"

它在 internet explorer 8 中运行良好,但在 mozilla fire fox 的情况下它无法运行。请说相同的解决方案在所有浏览器中运行。

提前致谢

问候 V.karthik

【问题讨论】:

  • 我正在更正标题,这样就不会得到不必要的否决票,因为您所追求的无缓存是完全有效的……只需“禁用后退按钮”即可有充分的理由不赞成 find :) 但这与您在这里所追求的不同。

标签: asp.net


【解决方案1】:

试试

Response.Cache.SetCacheability(HttpCacheability.NoCache)

【讨论】:

    【解决方案2】:

    查看这个问题的回答:

    Best way to disable client caching

    这是同一个问题,同一个问题(IE 工作,FF 不工作)和一个公认的解决方案。我在引用:

    Expires: Sun, 19 Nov 1978 05:00:00 GMT
    Last-Modified: Fri, 12 Jun 2009 08:01:46 GMT (the actual modification date)
    Cache-Control: store, no-cache, must-revalidate, post-check=0, pre-check=0
    

    编辑:

    您可以在页面的代码隐藏中设置前两个标题:

    this.Response.Cache.SetExpires(DateTime.Now);
    this.Response.Cache.SetLastModified(DateTime.Now);
    

    但实际上,执行以下操作即可停用缓存(另请参阅Whats the best way to deal with pages loaded via browser history in asp .net?):

    this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    this.Response.Cache.SetNoStore();
    

    这会生成以下标题:

    Cache-Control: no-cache, no-store
    Pragma: no-cache
    Expires: -1
    

    【讨论】:

    • 在哪里使用这个编码和我一样详细
    • 如何使用这些编码以及在哪里使用
    • 它不适用于 mozila firefox3.6.3 和 safari 4.0 请帮助我在所有浏览器中工作。并且说编码在哪里使用。我很挣扎。但它在 ie 和 google 中工作正常铬。
    • 例如,您可以在 Page_Load 事件处理程序中使用它。请注意,回发后,您应该重定向到其他页面。另见blog.httpwatch.com/2008/10/15/…
    • 我在页面加载事件中使用了这种编码,它只在 HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)) HttpContext.Current.Response 中起作用。 Cache.SetValidUntilExpires(False) HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches) HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache) HttpContext.Current.Response.Cache.SetNoStore() 在 mozilla 没有的情况下工作
    猜你喜欢
    • 2010-12-06
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多