Sun
ONE Active Server Pages Product Home Page Developer Site Version
 

ContentsPreviousNextIndex



Remarks: ASP Response Object AddHeader Method

To avoid any name ambiguity, the name of the header should not contain any underscores (_). The Request.ServerVariables collection interprets underscores as dashes in the header name. The following script causes a search for a header named "My-Header":

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

Because HTTP requires that all headers be sent before content, you must call the AddHeader method in your script before any output (such as that generated by HTML code or the Response object Write method) is sent to the client. The exception to this rule is when the Response object Buffer property is set to TRUE. If the output is buffered, you can call the AddHeader method at any point in the script, as long as it precedes any calls to the Response object Flush method. Otherwise, the call to AddHeader will generate a run-time error.

The following two examples illustrate this. In the first example, the page is not buffered. The script works, however, because the AddHeader method is called before the server sends the Web page to the client. If the order was reversed, the call to the AddHeader method would generate a run-time error.

<% Response.AddHeader "WARNING", "Error Message Text" %> 
<HTML> 
Some text on the Web page. 
</HTML> 

In the next example, the page is buffered, and as a result, the server will not send output to the client until all the ASP scripts on the page have been processed or until the Flush method is called. With buffered output, calls to the AddHeader method can appear anywhere the script, so long as they precede any calls to the Flush method. If the call to the AddHeader method appeared below the call to the Flush method in the preceding example, the script would generate a run-time error.

<% Response.Buffer = TRUE %> 
' Here is some text on your Web page. 
<% Response.AddHeader "WARNING", "Error Message Text" %> Here's some more interesting and illuminating text. 
<% Response.Flush %> 
<%= Response.Write("some string") %> 


ContentsPreviousNextIndex