HttpResponse.AppendHeader(String, String) 方法

定義

將 HTTP 標頭加入輸出資料流。Adds an HTTP header to the output stream.

public:
 void AppendHeader(System::String ^ name, System::String ^ value);
public void AppendHeader (string name, string value);
member this.AppendHeader : string * string -> unit
Public Sub AppendHeader (name As String, value As String)

參數

name
String

要加入輸出資料流的 HTTP 標頭名稱。The name of the HTTP header to add to the output stream.

value
String

附加到標頭的字串。The string to append to the header.

例外狀況

標頭在 HTTP 標頭送出之後被附加。The header is appended after the HTTP headers have been sent.

範例

下列範例會呼叫AppendHeader方法,將自訂標頭新增至傳送給要求用戶端的HttpResponse物件。The following example calls the AppendHeader method to add a custom header to the HttpResponse object sent to the requesting client.

Response.AppendHeader("CustomAspNetHeader", "Value1");
Response.AppendHeader("CustomAspNetHeader", "Value1")

備註

如果您AppendHeader使用方法來傳送快取專屬的標頭,同時使用快取物件模型(Cache-Control Cache)來設定快取原則,則與快取有關的 HTTP 回應標頭ExpiresLast-Modified、、、 Pragma使用快Vary取物件模型時,可能會刪除、和)。If you use the AppendHeader method to send cache-specific headers and at the same time use the cache object model (Cache) to set cache policy, HTTP response headers that pertain to caching (Cache-Control, Expires, Last-Modified, Pragma, and Vary) might be deleted when the cache object model is used. 此行為可讓 ASP.NET 維持最嚴格的設定。This behavior enables ASP.NET to maintain the most restrictive settings. 例如,假設有一個包含使用者控制項的頁面。For example, consider a page that includes user controls. 如果這些控制項有衝突的快取原則,將會使用最嚴格的快取原則。If those controls have conflicting cache policies, the most restrictive cache policy will be used. 如果一個使用者控制項設定標頭 "Cache-Control: Public",而另一個使用者控制項透過對的呼叫Cache-Control: PrivateSetCacheability設定更嚴格的標頭 "Cache-Control: Private",則會隨著回應傳送 "" 標頭。If one user control sets the header "Cache-Control: Public" and another user control sets the more restrictive header "Cache-Control: Private" via calls to SetCacheability, then the "Cache-Control: Private" header will be sent with the response.

如需標準 HTTP/1.1 標頭的清單,請參閱全球資訊網協會(W3C)網站上的超文字傳輸通訊協定--HTTP/1.1規格中的第14節「標頭欄位定義」。For a list of standard HTTP/1.1 headers, see section 14, "Header Field Definitions," in the Hypertext Transfer Protocol -- HTTP/1.1 specification on the World Wide Web Consortium (W3C) Web site.

適用於