asp.net 2.0取消页面缓存

最近在做asp.net的开发,用到gridview里面的操作,但是在执行更新操作后即使重新进行数据绑定也还是在弹出查看和编辑窗口时显示原有数据,原来还以为是没有更新彻底,但是最后才发现是缓存的问题。现在把解决方法贴上,共享。

取消缓存


客户端取消

<html>
<head>
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
</head>

服务器具端取消:

服务器端:
    Response.Buffer = true;
    Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
    Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
    Response.Expires = 0;
    Response.CacheControl = "no-cache";
    Response.Cache.SetNoStore();

Global里面:  
protected   void   Application_BeginRequest(Object   sender,   EventArgs   e)  
{  
        HttpContext.Current.Response.Cache.SetNoStore();  
}
<%@ OutPutCache Location="None"%>

页面基类:
public   class   PageBase   :   Page  
{  
      public   PageBase()   {}  

      protected   override   OnLoad(   EventArgs   e   )   {  
              Response.Cache.SetNoStore();  
              base.OnLoad();  
      }  
}  

最简单的办法 :-)
学CSDN的这个论坛,在URL后面随机的加一些没用的参数,我常用的是使用当前时间点,比如:
http://xxx/xxx/xxx.aspx?......&time=date().toString()

IE是用过URL来控制缓存的,这样就解决了,但是呢,有时候这个方法会失效,具体情况具体分析啦。

猜你喜欢

转载自blog.csdn.net/UniMagic/article/details/4030664