The AddHeader method adds an HTML caption with the specified value. This method often adds a new HTTP caption to the response. It does not replace an existing title with the same name. Once the caption is added, it cannot be deleted.
This method is intended for use by advanced users only. It is recommended that you use this method if other Response methods provide the functionality you need.
To avoid naming ambiguous, name cannot contain any underscore characters (_). The ServerVariables collection interprets the underscore character in the title as a backslash. For example, the following script causes the server to find a header name named My-header.<% Request.ServerVariables ("Http_my_header")%>
Because the HTTP protocol requires that all headers must be sent before the content, you must call AddHeader in the script before any output, such as the output generated by the HTML or Write method, is sent to the client. However, an exception is when the Buffer property is set to TRUE. If the output is buffered, you can call the AddHeader method anywhere in the script, as long as it executes before Flush. Otherwise, a call to AddHeader will result in a run-time error.
This is explained in the following two. asp files.
In the previous example, the page has no buffering. However, because the server will output
The AddHeader method is invoked before being sent to the client, so the script works correctly. If the order is reversed, the call to the AddHeader method will produce a run-time error.
------file2.asp----------<% response.buffer = TRUE%> here ' s some text on your Web page.<% Response.AddHeader "WA Rning "," Error message Text "%> Here's some more interesting and illuminating text.<% Response.Flush%> <%= Re Sponse. Write ("some string")%>
In the preceding example, the page is buffered, and the result is that the server will not send the output to the client until all ASP scripts on this page have been executed or the Flush method has been invoked. Calls to AddHeader in buffered output can appear anywhere in the script, just before the Flush call. In the previous example, if a call to AddHeader occurs after a call to Flush, the script will produce a run-time error.
You can use this method to send multiple copies of the same title with different values, such as www-authenticate headings.
The following example uses the AddHeader method to require the client to use BASIC authentication.
Note the previous script notifies only the client browser which authentication is used. If you use this script in a Web application, be sure to enable BASIC authentication for the Web server.