ASP.NET Response 對象的部分方法和屬性

來源:互聯網
上載者:User

標籤:

Response 對象: 返回到用戶端的輸出

(1)、方法: 

Response.Write() : 輸出資訊到用戶端

Response. Redirect() : 重新導向

Response .Clear() : 清除在緩衝區的所有HTML頁面

Response .End() :終止處理ASP.NET程式,並返回當時的狀況

Response.Flush() : 立刻送出緩衝區的HTML資料

Response. WriteFile() 讀取一個檔案,並且寫入用戶端輸出資料流(實質:開啟檔案,並且輸出到用戶端。)

(2)、屬性

Response.ContentType輸出資料流的內容類型,比如html(text/html) 、普通文本(text/pain)還是JPEG圖片(image/JPEG)。

Response.ContentEncoding輸出資料流的編碼

Response.Cookies   : 返回瀏覽器的cookies的集合

 

Response.Buffer : 設定緩衝資訊, true | false .預設是true

Response. Expires :  擷取或設定在瀏覽器上緩衝的頁到期之前的分鐘數, 設定為0,則立刻到期,  

屬性值的類型: System.Int32

在頁到期之前的分鐘數。

 

Response.ExpiresAbsolute :擷取或設定從緩衝中移刪除緩衝資訊的絕對日期和時間

屬性值: System.DateTime  ;該頁到期時的日期和時間。

Response.CacheControl : HTTP頭, 其值是Cacheability 枚舉。

其中: CacheControl , ExpiresAbsolute , Expires ,已被拋棄, 為了相容舊版本,所以寫著 。 

現在控制緩衝使用 Response 的cache 屬性:

Response.Cache :擷取網頁的緩衝策略(例如,到期時間、保密性設定和變化條款)

Response.Cache.SetExpires(): 設定緩衝到期日期

Response.Cache.SetNoStore() : // Sets the Cache-Control: no-store HTTP header. 和Response.CacheControl = "no-cache";作用一樣。/

 

Requst 對象:讀取瀏覽器傳來的請求報文資料。

Post方式資料:  Requst.Form[“”]

Url資料: Requst.QueryString[]

無論post還是url 都可以使用 Request[""]擷取

 

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();   /// Sets the Cache-Control: no-store HTTP header.

 用戶端禁用緩衝代碼如下:

<meta http-equiv="pragma" content="no-cache" />  <meta http-equiv="Cache-Control" content="no-cache, must-revalidate" /> <meta http-equiv="expires" content="0" />

 

ASP.NET Response 對象的部分方法和屬性

聯繫我們

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