ASP Response Object : AddHeader Method

The AddHeader method adds a HTML header with the specified value. It will not replace an existing header of the same name. Once a header has been added, it cannot be removed.

The method takes two mandatory arguments:

  • Name - The name of the new header variable. This name should not contain any underscores (_).
  • Value - The initial value of the new header variable.

Since the HTTP protocol requires that all headers be sent before content, you must not make any AddHeader method calls after your ASP script generates any output. If buffering is on (see Response.Buffer), then the AddHeader method may be called at any point before a call to Response.Flush.

Example:

<%
  Response.Buffer = True
  Response.Write "Hello World!"
  Response.AddHeader "MyHeader", "This is my header!"
  Response.Flush
%>
The above code is legal because buffering is on1. However, if Response.Buffer was instead set to False then the code would generate an error message.


Back to the ASP Response Object
Back to ASP Objects
1 Buffering is on by default on IIS 5.0

Resources:
http://www.devguru.com/
http://msdn.microsoft.com/asp/

All code is my own (and despite what CNN says, is not involved with the Taliban).

Log in or register to write something here or to contact authors.