0% found this document useful (0 votes)
58 views7 pages

The Response Object: Methods

The Response object in ASP allows adding HTTP headers to the server response. The AddHeader method adds a new header without replacing existing ones of the same name. Headers must be added before any output is sent to the client. Response buffering allows adding headers later in the ASP script by buffering the response. Common headers include Content-Type and Content-Disposition to control content handling.

Uploaded by

Shaishav Patel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views7 pages

The Response Object: Methods

The Response object in ASP allows adding HTTP headers to the server response. The AddHeader method adds a new header without replacing existing ones of the same name. Headers must be added before any output is sent to the client. Response buffering allows adding headers later in the ASP script by buffering the response. Common headers include Content-Type and Content-Disposition to control content handling.

Uploaded by

Shaishav Patel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 7

The Response Object: Methods

Response.AddHeader :: “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”.
AddHeader( HeaderName, HeaderValue)

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
%>

The above code is legal because buffering is on1. However, if


Response.Buffer was instead set to False then the code would generate an
error message.
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.
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"))
%>

You might also like