ASP Object: AddHeader

Source: Internet
Author: User
Tags object flush header servervariables variable client
Addheader|object

AddHeader

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.

Grammar

Parameters

Name
The name of the new title variable.
Value
The
initial value stored in the new header variable.

Comments

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.

Example

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.

Apply to

Response objects



Related Article

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.