Platform SDK: IIS SDK |
The AddHeader method adds a new HTML header and value to the response sent to the client. It does not replace an existing header of the same name. After a header has been added, it cannot be removed.
Response.AddHeader HeaderName, HeaderValue
If a client is configured to return response headers to the server on a subsequent request, you can use Request.ServerVariables to retrieve the custom header value. "HTTP_" is added to the beginning of the custom header name. For example, if you add a header with this code:
<% Response.AddHeader "CustomHeader", "CustomValue" %>
You can retrieve the header if a special client returns it to the server on the next request with the following code:
<% ReturnedValue =index.html Request.ServerVariables("HTTP_CustomHeader") %>
To avoid name ambiguity, HeaderName should not contain any underscore (_) characters. The ServerVariables collection interprets underscores as dashes in the header name. For example, the following script causes the server to search for a header named MY-HEADER:
<% Request.ServerVariables("HTTP_MY_HEADER") %>
If a different Response method can provide the functionality you require, it is recommended that you use that method instead. For example, to send a custom value and have it returned to your Web application on a subsequent request without relying on the configuration of the client, you can use Response.Cookies and Request.Cookies. Or to set cache control for a response, you can use Response.CacheControl.
Because the HTTP protocol requires that all headers be sent before the page content, you must modify all outgoing headers before your ASP script generates any output. In IIS 4.0, this meant that you had to call the AddHeader method in your script before any output was sent to the client, such as output generated by HTML code or the Response.Write method. In IIS versions 5.0 or later, response buffering is on by default. Therefore, you can call the AddHeader method at any point in the script, as long as it precedes any calls to the Response.Flush method. You can enable or disable response buffering by setting the metabase property AspBufferingOn or by using Response.Buffer in an ASP script.
The following .asp file illustrates this point.
<HTML>
Here's some text on your Web page.
' This header tells proxy servers using HTTP/1.0 not to cache this request.
<% Response.AddHeader "Pragma", "no-cache" %>
<% Response.Flush %>
<% Response.Write("Pragma is set to no-cache") %>
</HTML>
In the preceding example, because the page is buffered by default, the server will not send output to the client until all the scripts on the ASP page have been processed or until the Response.Flush method is called. If the call to AddHeader appeared after the call to Flush in the preceding example, the script would generate a run-time error.
You can use the AddHeader method to send multiple copies of the same header with different values, as with the WWW-Authenticate headers. The following example uses the AddHeader method to request that the client use Basic authentication:
<% Response.Addheader "WWW-Authenticate", "BASIC" %>
The preceding script only informs the client browser of which type of authentication to use; it does not specify that the Web server enable Basic authentication for the application.
Platforms: Windows 2000 with IIS 5.0 installed,
Windows XP with IIS 5.1 installed,
Windows Server 2003 family with IIS 6.0 installed
What did you think of this topic? |
Order a Platform SDK CD |
file: /Techref/language/asp/obj/ref_vbom_resomah.htm, 6KB, , updated: 2003/5/15 13:13, local time: 2024/11/22 08:52,
18.188.132.71:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://sxlist.com/techref/language/asp/obj/ref_vbom_resomah.htm"> Response.AddHeader</A> |
Did you find what you needed? |
Welcome to sxlist.com!sales, advertizing, & kind contributors just like you! Please don't rip/copy (here's why Copies of the site on CD are available at minimal cost. |
Welcome to sxlist.com! |
.