Name

AddHeader — Response.AddHeader strName, strValue

Synopsis

Allows you to add your own HTTP response header with a corresponding value. If you add an HTTP header with the same name as a previously added header, the second header will be sent in addition to the first; adding the second header does not overwrite the value of the first header with the same name. Also, once the header has been added to the HTTP response, it cannot be removed.

If the client sends the web server an HTTP header other than those listed in the section on the ServerVariables collection in Chapter 7, you can use HTTP_HeaderName to retrieve it. For example, if the client sends the HTTP header:

                     ClientCustomHeader:CustomHeaderValue

then you could retrieve the value for this element using the following syntax:

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

This is an advanced method and should not be used without careful planning. If another method of the Response object will meet your needs, use it instead of using the AddHeader method.

Parameters

strName

The name of the HTML header you wish to add to the response header

strValue

The initial value of the new header you are adding to the response header

Example

<% 
' The following code adds the CUSTOM-ERROR HTML header to 
' the HTTP response headers.
Response.AddHeader "CUSTOM-ERROR", "Your browser is not IE."
%>

Notes

Like the other methods and properties of the Response object that alter the HTTP response headers, you must call the AddHeader method before ...

Get ASP in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.