去年做的一个系统,不晓得怎么回事,总是出现莫名其妙的问题,今天才明白原来是缓存问题,去年一直以为是服务器缓存,结果是客户端缓存问题。
解决办法,每个页面调用下面这个方法就可以了
///
/// 清空浏览器客户端的缓存
///
public static void ClearClientPageCache()
{
HttpContext.Current.Response.Buffer=true;
HttpContext.Current.Response.Expires = 0;
HttpContext.Current.Response.ExpiresAbsolute=DateTime.Now.AddDays(-1);
HttpContext.Current.Response.AddHeader("pragma","no-cache");
HttpContext.Current.Response.AddHeader("cache-control","private");
HttpContext.Current.Response.CacheControl="no-cache";
}
/// 清空浏览器客户端的缓存
///
public static void ClearClientPageCache()
{
HttpContext.Current.Response.Buffer=true;
HttpContext.Current.Response.Expires = 0;
HttpContext.Current.Response.ExpiresAbsolute=DateTime.Now.AddDays(-1);
HttpContext.Current.Response.AddHeader("pragma","no-cache");
HttpContext.Current.Response.AddHeader("cache-control","private");
HttpContext.Current.Response.CacheControl="no-cache";
}
参考
原文http://blog.csdn.net/zhangxiaoxiang/archive/2006/05/14/727904.aspx