HttpResponse.AppendHeader(String, String) HttpResponse.AppendHeader(String, String) HttpResponse.AppendHeader(String, String) HttpResponse.AppendHeader(String, String) Method

定义

将 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 String String String

要添加到输出流的 HTTP 头的名称。The name of the HTTP header to add to the output stream.

value
String String String 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)来设置缓存策略,请参阅与缓存相关的 HTTP 响应标头(Cache-ControlExpiresLast-ModifiedPragma使用缓存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",而另一个用户控件通过调用来SetCacheability设置Cache-Control: Private限制性更强的标头 ""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.

适用于