The Response Object: Methods
The Response Object: Methods
Parameters
HeaderName
A string that indicates the name of the new header.
HeaderValue
A string that indicates the initial value of the new header.
Since the HTTP protocol requires that all headers be sent before content,
you must not make any AddHeader method calls after your ASP script
generates any output. If buffering is on (see Response.Buffer), then the
AddHeader method may be called at any point before a call to
Response.Flush.
The Response Object: Methods
Response.AddHeader :: Example
<%
Response.Buffer = True
Response.Write "Hello World!"
Response.AddHeader "MyHeader", "This is my header!"
Response.Flush
%>
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.
What Are HTTP Headers?
HTTP headers are an Internet protocol, or set of rules for formatting certain types
of data and instructions that can be sent along with a request from a web client
or browser, or sent by the server along with a response to a browser. In simpler
terms, an HTTP header is a few lines of code that carries information between
a browser and a Web server.
Response.AddHeader("Content-Disposition", _
"attachment; filename=" & strClientFileName)
Response.AddHeader("Content-Disposition", _
"inline; filename=" & strClientFileName)
attachment - forces download
inline - forces the browser to open the content inline if possible (default)
<filename> - you can specify the file name under which the download should be
saved (makes sense only with attachment).
<%
Response.AddHeader "Refresh", "10; URL=http://www.WebSiteName.com"
%>
GET /index.html HTTP/1.1
Host: www.google.com
From: [email protected]
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)
Date: Fri, 27 Jun 2008 00:22:19 GMT
Expires: -1
Cache-Control: private, must-revalidate, max-age=0
Content-Type: text/html; charset=UTF-8
Last-Modified: Fri, 27 Jun 2008 00:22:18 GMT
Etag: 9398183226707537952
Set-Cookie: IGTP=LI=1:LM=1214526139; expires=Sun, 27-Jun-2010 00:22:19
GMT; path=/ig;
domain=www.google.com
Content-Encoding: gzip
Server: igfe
Content-Length: 49301
X-Cache: MISS from proxy2.online.com.kh
Via: 1.0 proxy2.online.com.kh:3128 (squid/2.6.STABLE20)
Connection: keep-alive
200 OK
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%
Response.Write "Writing to log fie...<br/>"
Response.AppendToLog "Isnt this useful?"
Response.Write "Log fie written...<br/>"
%>
<%
Set objRS = objConn.Execute("SELECT Picture FROM TableName WHERE ID = 1")
Response.ContentType = "image/gif"
Response.BinaryWrite(objRS("Picture"))
%>