asp.net中禁止頁面緩衝程式碼

來源:互聯網
上載者:User

方法一:導航時用伺服器端的Response.Redirect方法,或者用前端得window.location.replace方法。

方法二:禁用ASP.NET頁面緩衝。

在必要的時候我還是推薦方法二的。因為我們做開發的不能控制瀏覽器的設定。使用者如果把IE設定為從不檢查更新緩衝的問題則不好避免,所以還是用方法二,讓IE的臨時檔案夾不存在分頁檔。

另外,是否禁用頁面緩衝要根據實際情況來說,起初我認為頁面緩衝只是緩衝在伺服器,後來看了一篇blog

發現緩衝的意義還是很大的。在很多情況下可以大大減小伺服器的壓力。只不過開發過程中要多多從需求出發,不能盲目的設定什麼屬性。


直接在瀏覽器中禁止

 代碼如下 複製代碼

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


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

全域配置 Global

 代碼如下 複製代碼

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

Aspx頁面

 代碼如下 複製代碼

<%@ OutPutCache Location="None"%>

C#中禁止cache的方法!

 代碼如下 複製代碼

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.