設(shè)置ASP.NET頁面不被緩存(客戶端/服務(wù)器端取消緩存方法)
更新時(shí)間:2013年06月24日 16:18:09 作者:
設(shè)置頁面不被緩存:客戶端取消緩存、服務(wù)器具端取消緩存的具體實(shí)現(xiàn)代碼如下感興趣的朋友可以參考下哈,希望對(duì)大家有所幫助
復(fù)制代碼 代碼如下:
/// <summary>
/// 設(shè)置頁面不被緩存
/// </summary>
private void SetPageNoCache()
{
Response.Buffer = true;
Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
Response.Expires = 0;
Response.CacheControl = "no-cache";
Response.AppendHeader("Pragma", "No-Cache");
}
1、取消緩存
(2)客戶端取消
復(fù)制代碼 代碼如下:
<html>
<head>
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
</head>
(3)服務(wù)器具端取消:
服務(wù)器端:
復(fù)制代碼 代碼如下:
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里面:
復(fù)制代碼 代碼如下:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
HttpContext.Current.Response.Cache.SetNoStore();
}
<%@ OutPutCache Location="None"%>
頁面基類:
復(fù)制代碼 代碼如下:
public class PageBase : Page
{
public PageBase() {}
protected override OnLoad( EventArgs e ) {
Response.Cache.SetNoStore();
base.OnLoad();
}
}
最簡(jiǎn)單的辦法 :-)
學(xué)CSDN的這個(gè)論壇,在URL后面隨機(jī)的加一些沒用的參數(shù),比如:
http://xxx/xxx/xxx.jpg?p=xxx
IE是用過URL來控制緩存的,這樣就解決了
相關(guān)文章
ASP.NET TreeView讀取數(shù)據(jù)庫(kù)實(shí)例
這篇文章主要介紹了ASP.NET TreeView讀取數(shù)據(jù)庫(kù)實(shí)例,有需要的朋友可以參考一下2013-11-11asp.net 產(chǎn)生隨機(jī)顏色實(shí)現(xiàn)代碼
asp.net 隨機(jī)顏色產(chǎn)生實(shí)現(xiàn)代碼,需要的朋友拿過去測(cè)試一下。2009-11-11