|
|
|
|
More of the Request and Response Object
This property tells the browser how long the page lives since the time it was last updated. In other words, it controls how the browser caches the page and after what period of time the browser ignores the page from the cache. If you set the value to zero, the page will always be refreshed. To set this property, use the following syntax:
Like the Expires property, this property, too, sets the time after which the page should be ignored from the cache. The difference is that here the date and time are explicitly declared, instead of the amount of time since the last visit. The syntax is: Response.ExpiresAbsolute = #Date Time# The time is converted to GMT before the header is sent, since this is the time used by all servers to stay
synchronized. If the Time field is left blank, the value defaults to midnight on the given date. If the Date field is skipped, the value defaults to the current date. This property sends any response value set for it to the client. The syntax for this is: Response.Status ="<Status>" where Status is a three digit number followed by a description. Status values are defined in the HTTP specification. For the current complete listing, refer to the appendix.
The methods of the Response Object have been listed in an earlier chapter. We have already seen the Write method of the Response Object. The rest are discussed below.
This method adds headers to the HTML output stream. These headers are generally understood by most or all client browsers. Headers are a means of communication from the server to the client and are transparent to the user. This is the general syntax: Response.AddHeader "<HeaderName>", "Value"
If IIS is configured to log transactions, this method can write a string of maximum 80 characters to the log. Be careful, though.
The IIS log file is delimited by commas, so you cannot use these in your string. You can, however, URLEncode the string before writing it to the log and decode it later when retrieving it. The syntax for writing to the log file is:
This method sends binary files to the client. For example, you may use it to send images to the client. The syntax for binary output is: Response.BinaryWrite <BinaryData> Example:<%' Code to retrieve an image from a database field imgPicture = rs.Fields("UserImage") Response.BinaryWrite imgPicture %> In this example, the database stores images in an OLE field named UserImage. The database is opened and a recordset is retrieved in a recordset object named rs. A variable named imgPic ture then picks up the data from UserImage field of the current record (we will learn about databases in a later chapter). The BinaryWrite method writes this image to the HTML output stream. , The Clear method erases the contents of the Response Object that would have been output to the HTML stream. This works only if the Buffer property is set to True. It erases only the body of the Response Object; not the headers. This is particularly
useful in handling errors: The developer can simply clear the Response buffer and start running the script over again or jump to another point. The syntax for clearing the Response buffer is: This method terminates processing all ASP scripts. The current result, if any, is returned and no further scripts on the page are executed. If the Buffer property is set to True, the buffer is flushed. The syntax is: Response.End
If the Buffer property has been set to True, this method sends the contents of the Response buffer to the client (the HTML output stream). The syntax for this is: Response.Flush
This method redirects the client to a different URL. This can be important if the structure of the Web site changes and the user attempts to use a bookmark to a page that no longer exists. This can also be used when access to a page depends on certain criteria, like a member's login. The syntax for redirecting users is: Response.Redirect <URL>"Example: <% If Session("SuccessfulLogin") = False Then Response.Redirect ("login..asp") Else Response.Redirect("http://www.myserver.com/asp/tutorial/members/" End If %> |