|
The Response Object
The ASP Response object is used to send output to the user from the server. Its collections, properties, and methods are described below:
Collections
Description
|
Cookies
|
Creates a cookie and sets a cookie value. If the cookie does not exist, it will be created, and take the values that are specified by you via scripting.
Scripting syntax: Response.Cookies(name)[(key).attribute]=value "Name" is the name of the cookie it is a required Value ".Attribute" is optional information about or for the cookie Attributes can be one of the following:
- .Domain
Write-only. The cookie is sent only to requests to this domain
- .Expires
Write-only. The date when the cookie expires. If no date is specified, the cookie will expire when the session ends
- .HasKeys
Read-only. Specifies whether the cookie has keys
- .Path
Write-only. When set, the cookie is sent only to requests to this path.
- .Secure
Write-only. Indicates the cookie is secure
|
|
"Key" is the identifier in the cookie [like a field in a table] "Value" is the value stored in the Key or the cookie attribute.
Example: Response.Cookies("gotfusion.com")("name")=request.form("Name") This will create a cookie with the name of gotfusion.com having a key named name and gathering the content of the key via a form field action. or Response.Cookies("gotfusion.com").Expires=#June 30,2004# This will create a cookie called gotfusion.com and will expire on June 30th, 2004
|
|
Properties
Description
|
Buffer
|
Specifies whether to buffer the page output or not Examples:
response.buffer = True response.buffer=False
You will normally want this set to True when working with forms data. False indicates no buffering. The server will send the output as it is processed. In many ways this is slower as it write bit's and pieces at a time slowing performance of your page.
True indicates buffering. The server will not send output until all of the scripts on the page have been processed, or until the Flush or End method has been called.
|
CacheControl
|
Sets whether a proxy server can cache the output generated by ASP or not Syntax examples are:
response.CacheControl="Public" response.CacheControl="Private"
This property can be set to either "Public" or "Private". Private is default and indicates that only private caches may cache the asp results page. Proxy servers will not cache pages with this setting.
Public indicates public caches. Proxy servers will cache all asp result pages with this setting.
By default the CacheControl property is set to Private.
|
Charset
|
Appends the name of a character-set to the content-type header in the Response object. Syntax: response.Charset = "value" If you did not specify a Charset set in NOF for whatever reason, you can using this method set it. For example:
response.Charset="ISO-8859-1" In issuing this statement , the content-type header would be changed to include the charset of your choice. The result for the above example would be seen in the resulting source of the ASP page served up by the server and would read
content-type:text/html; charset=ISO-8859-1
By default ASP assumes and sets the Charset to ISO-LATIN-1if one is not specified or programmed into the ASP page
|
ContentType
|
Sets the HTTP content type for the Response object. If you are coding in NetObjects Fusion the Content type is set by Fusion and will be: content-type:text/html
Syntax: response.ContentType="value"
If you are handcoding a few result pages, you can set the content type to whatever you wish. If you are serving up a results page and want to create an excel spreadsheet from the data and open excel in the browser window; you can indicate the content type before writing any data from the server by using the following syntax
response.ContentType="application/vnd.ms-excel"
Other ContentTypes: image/GIF image/JPEG text/plain
Caution: the user must have the application installed and a file association created with these other content types. If you are not sure just use the default. By default asp assumes content-type:text/html
|
Expires
|
Sets in minutes how long a page will be cached on a browser before it expires. Syntax: response.expires = number of minutes If you never want to cache your ASP results page set this value to -1 If you want to give some time before the page expires increase the value
|
ExpiresAbsolute
|
Sets a date and time when a page cached on a browser will expire. If this is not specified the page will expire at the date and time run at the server. syntax: response.ExpiresAbsolute[=#[date][time]#] Date specifies the date the page will expire Time specifies the Time it will expire For Example:
response.ExpiresAbsolute=#June 10,2003 17:00:00#
|
|
will keep and re-display the ASP results page until June 10, 2003 at 5PM
|
IsClientConnected
|
Indicates if the client has disconnected from the server Syntax: response.IsClientConnected The value is served up by the server and could be used in a ASP Chat room session to indicate whether a visitor is still active in the site for Example:
<% If response.IsClientConnected=false then response.write rs("Name") & "Has left the ChatRoom!" end if %>
|
|
|
Pics
|
Appends a value to the PICS label response header The PICS (Platform for Internet Content Selection) rating system is used to rate the content in a web site. Syntax: response.PICS(picslabel)
Note: PICS labels contain quotes. Replace any quotes in your syntax with " & chr(34) & " or your page will not display. Unless you are sure what you are doing ignore formatting the rating system for your page unless the content is harsh and not suitable for children.
Example Syntax: <% response.PICS("(PICS-1.1 <http://www.rsac.org/ratingv01.html> by " & chr(34) & "you@gotfusion.com" & chr(34) & " for " & chr(34) & "http://www.gotfusion.com" & chr(34) & " on " & chr(34) & "2003.06.06T02:15-0800" & chr(34) & " r (n 2 s 0 v 1 l 2))") %>
Using the above will produce a header added to your asp page as shown below.
PICS-label:(PICS-1.1 <http://www.rsac.org/ratingv01.html> by "you@gotfusion.com" for "http://www.gotfusion.com" on "2003.06.06T02:15-0800" r (n 2 s 0 v 1 l 2))
|
|
Methods
AddHeader
|
The AddHeader method adds a new HTTP header and a value to the HTTP response.
Note: Once a header has been added, it cannot be removed. In IIS 4.0 you have to call this method before any output is sent to the browser. In IIS 5.0 you can call the AddHeader method at any point in the script, as long as it place before any calls to the response.Flush method.
Syntax: response.AddHeader name,value
Example: Response.AddHeader "Contest","Contest Entry for " & rs("name")
|
AppendToLog
|
Adds a string to the end of the server log entry You can call this method multiple times in a script. Each time it is called it will append the specified value to the log entry.
Syntax: response.AppendToLog "value" Example: Response.AppendToLog "At this time" & rs("name") & ", accessed site and received the information from form: " & request.servervariables("SCRIPT_NAME")
|
BinaryWrite
|
The BinaryWrite method writes data directly to the resulting page view without any character conversion. This is used for displaying images or BLOB's stored in the database.
Syntax: response.BinaryWrite "value" Example:response.BinaryWrite rs("graphic") Please note that when an image is displayed in this method, a right click on the image and choosing "save image as" will result in the image taking the file name of the calling asp page.
|
Clear
|
Clears any buffered HTML output Syntax: response.Clear I have never personally used this method although I am sure it has a useful purpose. Just can't think of an example, unless you would want to keep information from the visitors view, in which case you would use this in conjunction with the end method. Please Note: If response.buffer is set to False running this method will cause an run-time overflow.
|
End
|
Stops processing a script, and returns the current result Syntax: response.end
Note: This method will flush the buffer if Response.Buffer has been set to true. If you do not want to return any output to the user, you can call Response.Clear first.
Example: Response.clear Response.end
|
Flush
|
Sends buffered HTML output immediately Syntax: Response.Flush
Note: If response.Buffer is false, using this method will cause an run-time error.
|
Redirect
|
Redirects the user to a different URL Syntax: response.redirect "url" Once processing is finished you may wish to redirect users to a Thank you page or in the case of a logon routine redirect the visitor to the main site.
Example: If userx = rs("user") and passwordx = rs("password") then response.redirect "http://www.gotfusion.com/tutsMK/asp" Else response.write "<a href='http://www.gotfusion.com/login'>Login Failed, Please try again</a>" end if
|
Write
|
Writes a specified string to the output Syntax: Response.write This is the most commonly used method as it is this method that adds written content to the results page.
|
|
|