Asp Object: AddHeader

Source: Internet
Author: User
AddHeader
The AddHeader method adds the HTML title with the specified value. This method often adds a new HTTP title to the response. It does not replace the existing title with the same name. Once the title is added, it cannot be deleted.
This method is only for advanced users. If other Response methods provide the functions you need, we recommend that you use this method.
Syntax Response. AddHeader name, value

Parameters
Name
Name of the new title variable.
Value
The initial value stored in the new title variable.
Note
To avoid ambiguous names, the name cannot contain any underscore (_). The ServerVariables set interprets the underline characters in the title as a backslash. For example, the following script allows the server to search for a title named MY-HEADER. <% Request. ServerVariables ("HTTP_MY_HEADER") %>
Because HTTP requires that all headers must be sent before the content, you must output any content (for example, the output generated by the HTML or Write method) call AddHeader in the script before sending it to the client. Except when the Buffer attribute is set to TRUE. If the output is buffered, you can call the AddHeader method anywhere in the script as long as it is executed before being flushed. Otherwise, the AddHeader call will generate a running error.
The following two. asp files explain this point. ------- File1.asp ---------
<% Response. AddHeader "WARNING", "Error Message Text" %>
<HTML>
Some text on the Web page.
</HTML>

In the previous example, the page is not buffered. However, because the server will output Some text on the Web page

The AddHeader method is called before being sent to the client, so the script works properly. If the order is changed, the AddHeader method call will generate a runtime error. ------ File2.asp ----------
<% Response. Buffer = TRUE %>
<HTML>
Here's 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") %>
</HTML>

In the previous 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 the page are executed or the Flush method is called. The AddHeader call in the buffer output can appear anywhere in the script, as long as it is before the Flush call. In the previous example, if AddHeader is called after Flush, the script will generate a runtime error.
You can use this method to send multiple copies of the same title with different values, for example, WWW-Authenticate.
Example
The following example uses the AddHeader method to require the client to use BASIC verification. <% Response. Addheader "WWW-Authenticate", "BASIC" %>

Note that the preceding script only notifies the client browser of which verification is used. If you use this script in a Web application, you must enable BASIC verification for the Web server.
Apply
Response object

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.