[This is preliminary documentation and subject to change]

### AddHeader

The AddHeader method adds a new HTML header and value to the response sent to the client. It does not replace an existing header of the same name. Once a header has been added, it cannot be removed.

###### Syntax

Response.AddHeader HeaderName, HeaderValue

###### Parameters

HeaderName
  A string that indicates the name of the new header.
HeaderValue
  A string that indicates the initial value of the new header.

###### Note

If a client is configured to return response headers back to the server on a subsequent request, you may use Request.ServerVariables to retrieve the custom header value. "HTTP_" will be pre-pended to the custom header name. For example, if you add a header with this code:

    <% Response.AddHeader "CustomHeader", "CustomValue" %>

You can retrieve the header if a special client returns it to the server on the next request with this code:

    <% ReturnedValue = Request.ServerVariables("HTTP_CustomHeader") %>

To avoid name ambiguity, HeaderName should not contain any underscore (_) characters. The ServerVariables collection interprets underscores as dashes in the header name. For example, the following script causes the server to search for a header named MY-HEADER.

    <% Request.ServerVariables("HTTP_MY_HEADER") %>

If another Response method can provide the functionality you require, it is recommended that you use that method instead. For example, to send a custom value and have it returned to your Web application on a subsequent request without relying on the configuration of the client, you can use Response.Cookies and Request.Cookies; or to set cache control for a response, use Response.CacheControl.

Because the HTTP protocol requires that all headers be sent before content, you must modify all outgoing headers before your ASP script generates any output. In IIS 4.0, this meant that you had to call AddHeader in your script before any output was sent to the client, such as output generated by HTML code or the Write method. In IIS versions 5.0 or later, response buffering is on by default. Therefore, you can call the AddHeader method at any point in the script, as long as it precedes any calls to Flush. You can enable or disable response buffering by setting the metabase property AspBufferingOn or making a call to Response.Buffer in an ASP script.

The following .asp file illustrates this point.

    <HTML>
    Here's some text on your Web page.
    ' This header tells proxy servers using HTTP/1.0 not to cache this request.
    <% Response.AddHeader "Pragma", "no-cache" %>
    <% Response.Flush %>
    <% Response.Write("Pragma is set to no-cache") %>
    </HTML>

In the preceding example, because the page is buffered by default, the server will not send output to the client until all the scripts on the ASP page have been processed or until the Flush method is called. If the call to AddHeader appeared after the call to Flush in the preceding example, the script would generate a run-time error.

###### Example

You can use AddHeader to send multiple copies of the same header with different values, as with the WWW-Authenticate headers. The following example uses the AddHeader method to request that the client use Basic authentication.

    <% Response.Addheader "WWW-Authenticate", "BASIC" %>

The preceding script only informs the client browser which type of authentication to use; it will not tell your Web server to enable Basic authentication for the application.

###### Applies To

Response Object

###### See Also

Flush, Write, Buffer

© 1997-2001 Microsoft Corporation. All rights reserved.