禁用浏览器缓存从ASP.NET所有的浏览器 [英] Disabling browser caching for all browsers from ASP.NET

查看:137
本文介绍了禁用浏览器缓存从ASP.NET所有的浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个明确的参考一下ASP.NET code需要从缓存的页面浏览器禁用后我。有许多方法来影响HTTP标题和meta标签,我得到了IM pression需要不同的设置,以获得不同的浏览器正常运行。这将是真正伟大的得到code的参考位注释指示哪些适用于所有浏览器和其所需的特定浏览器,包括版本。

有一个巨大的对这个问题有信息量,但我还没有找到一个描述每一种方法和好处一个很好的参考是否特定的技术已经由更高级别的API取代。

我在ASP.NET 3.5 SP1特别感兴趣,但是这将是很好的得到早期版本的答案为好。

本博客条目<一个href=\"http://blog.httpwatch.com/2008/10/15/two-important-differences-between-firefox-and-ie-caching/\">Two Firefox和IE缓存介绍了一些HTTP协议的行为差异之间的重要区别。

下面的示例code说明了什么样的事情,我很感兴趣。

 公共抽象类NoCacheBasePage:System.Web.UI.Page
{
    保护覆盖无效的OnInit(EventArgs的发送)
    {
        base.OnInit(E);        DisableClientCaching();
    }    私人无效DisableClientCaching()
    {
        //做这些结果在META标签例如&LT; META HTTP-EQUIV =过期CONTENT = - 1&GT;
        // HTTP头或两者兼而有之?        //这是否仅适用于IE浏览器的工作?
        Response.Cache.SetCacheability(HttpCacheability.NoCache);        //难道这需要火狐?将是很好的做到这一点没有神奇的字符串。
        //不能将其覆盖previous设置
        Response.Headers.Add(缓存控制,无缓存,无店);        //为什么需要显式调用setExpires中。 presume它仍然比打电话更好
        // Response.Headers.Add(直接
        Response.Cache.SetExpires(DateTime.UtcNow.AddYears(-1));
    }
}


解决方案

这就是我们在ASP.NET使用方法:

  //停止高速缓存在IE浏览器
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);//停止高速缓存在Firefox
Response.Cache.SetNoStore();

它停止缓存在Firefox和IE浏览器,但我们还没有尝试过其他的浏览器。下面的响应报头将这些语句添加:

 的Cache-Control:no-cache的,无店
编译:无缓存

I'm after a definitive reference to what ASP.NET code is required to disabled browsers from caching the page. There are many ways to affect the HTTP headers and meta tags and I get the impression different settings are required to get different browsers to behave correctly. It would be really great to get a reference bit of code commented to indicate which works for all browsers and which is required for particular browser, including versions.

There is a huge amount of information about this issue there but I have yet to find a good reference that describes the benefits of each method and whether a particular technique has been superseded by a higher level API.

I'm particularly interested in ASP.NET 3.5 SP1 but it would be good to get answers for earlier version as well.

This blog entry Two Important Differences between Firefox and IE Caching describes some HTTP protocol behaviour differences.

The following sample code illustrates the kind of thing I am interested in

public abstract class NoCacheBasePage : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        DisableClientCaching();
    }

    private void DisableClientCaching()
    {
        // Do any of these result in META tags e.g. <META HTTP-EQUIV="Expire" CONTENT="-1">
        // HTTP Headers or both?

        // Does this only work for IE?
        Response.Cache.SetCacheability(HttpCacheability.NoCache);

        // Is this required for FireFox? Would be good to do this without magic strings.
        // Won't it overwrite the previous setting
        Response.Headers.Add("Cache-Control", "no-cache, no-store");

        // Why is it necessary to explicitly call SetExpires. Presume it is still better than calling
        // Response.Headers.Add( directly
        Response.Cache.SetExpires(DateTime.UtcNow.AddYears(-1));
    }
}

解决方案

This is what we use in ASP.NET:

// Stop Caching in IE
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);

// Stop Caching in Firefox
Response.Cache.SetNoStore();

It stops caching in Firefox and IE, but we haven't tried other browsers. The following response headers are added by these statements:

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

这篇关于禁用浏览器缓存从ASP.NET所有的浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆