在Asp.net项目中禁止浏览器缓存页面

方法1:在asp.net服务器端页面中添加如下代码段(只是作用于某个特定的页面)

<%
    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();
%>

方法2:在Global.asax.cs文件中的特定方法中加入如下代码段(作用于整个工程)

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    HttpContext.Current.Response.Cache.SetNoStore();
}

方法3:在服务器端页面对应的隐藏代码文件中加入如下代码段(作用于特定页面)

Response.Buffer=true;
Response.ExpiresAbsolute=System.DateTime.Now.AddSeconds(-1);
Response.Expires=0;
Response.CacheControl="no-cache";

 

posted @ 2013-07-11 18:03  smilepy  阅读(509)  评论(0编辑  收藏  举报