我想要的是一个关于ASP.NET代码是禁用浏览器缓存页面所必需的.有很多方法可以影响HTTP头和元标记,我得到的印象是,不同的浏览器需要不同的设置才能正常运行.如果能得到一段参考代码来说明哪些适用于所有浏览器,哪些是特定浏览器(包括版本)所必需的,那就太好了.
关于这个问题有大量的信息,但我还没有找到一个好的参考文献来描述每种方法的优点,以及某项特定技术是否已被更高级别的API取代.
我对ASP.NET3.5SP1特别感兴趣,但如果能得到早期版本的答案也会很好.
本博客条目Two Important Differences between Firefox and IE Caching描述了一些HTTP协议行为差异.
下面的示例代码说明了我感兴趣的内容
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));
}
}