asp.net裡如何清空頁面緩衝的後台代碼

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   使用   sp   strong   資料   

asp.net裡如何清空頁面緩衝的後台代碼(因為只有GET請求會有緩衝)
 
  題描述:當使用ajax的時候,很有可能出現同一次請求,這裡。比如buttonA修改了資料,而buttonB匯出資料,如果兩個按鈕都採用ajax的技術來做的話,實際上buttonB在第二次點擊以後,不會重新從資料庫裡獲得一次資料,而是直接將快取頁面發送給用戶端。恩~這麼做是好的,但是不是我們希望的。所謂使用了Ajax產生了不可預計的結果,有一部分可能也許就在於此。所以我要做的就是每次GET請求的時候都去清空緩衝,然後再產生頁面發送給用戶端。代碼如下:
 #region 清空用戶端頁面緩衝 :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"; } #endregion 在需要的地方調用即可。

asp.net裡如何清空頁面緩衝的後台代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.