The Redirect Method

Buffering the Response Message

To prevent the Web server from sending the HTTP response to the user until all server-side script on the current ASP has been processed , you can buffer the content of the response message.
Note

Waiting for the server to finish processing all server-side script may cause a lengthy delay. To send pieces of the response to the user before processing is complete, use the Flush method of the Response object throughout your code.


Before you continue with the lesson, run the Chap10b.exe animation located on the CD-ROM that accompanies this book. This animation explains how IIS uses buffering when creating a response to a client.

Setting the Buffer Property

To enable buffering, set the Buffer property to True. The Buffer property cannot be set after the server has sent output to the user. For this reason, set the Buffer property in the first line of the .asp file.

Example

This example sets the Buffer property to true:
 Response.Buffer = True 

Handling Errors with Buffering

If an error occurs during processing, use the Redirect method of the Response object, with buffering enabled. First, clear the buffer with the Clear method, and then use the Redirect method.

Example

This example clears the buffer and redirects the user to an error page after an error occurs:
 Response.Buffer = True On Error Resume Next 'code that may cause an unrecoverable error, 'such as failing to open a data connection If Err.number <> 0 Then Response.Clear Response.Redirect "error.htm" End If 

Lesson Summary

After you have determined what information the user requested , you can respond to the request by using the Response object. The Response object has properties and methods that you can use to control the information sent to a user. Some of the common properties include Buffer , Expires , and ExpiresAbsolute . Common methods of the Response object include Clear , End , Flush , Redirect , and Write .

The Write method adds text to an HTTP request, and the Redirect method jumps to a different URL. Use the Buffer property to prevent the Web server from sending the HTTP response to the user until all server-side script on the current ASP has been processed.



Microsoft Windows Architecture Training
Microsoft Windows Architecture for Developers Training Kit
ISBN: B00007FY9D
EAN: N/A
Year: 1998
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net