Client Connection

Overview

If your Web-based application performs complicated or time-consuming calculations or procedures, it is often useful for it to periodically check-in with the client browser and confirm that they are, indeed, still connected to the server. For instance, an on-line catalog application could check the client browser's connection before and after performing each computationally-intensive operation, such as creating an individual catalog item page from a database, or generating a purchasing invoice. If at any time it discovers that the connection has been abandoned, the application can destroy the session state information, and free the server's resources for other tasks.

Code Tour

This sample simulates an application that performs time-consuming calculations. A message is sent to the client browser that the application is about to perform a time-consuming operation, which in this case is simply a large loop. After the operation, the script checks the Response.IsClientConnected property to determine whether the client browser is still connected. If they are still connected, another time-consuming loop is performed, followed by another Response.IsClientConnected check. If the client browser remains connected, the user is rewarded with a thank you message.

Note   Response.IsClientConnected will provide accurate connection status, whether buffering is turned on or off. If the client is operating through certain types of proxies, however, the connection may still seem to be valid, even if the client has already disconnected.

Location

The VBScript and JScript versions of this script are available in the IIS samples directory, at ...\asp\interaction\Cancel_VBScript.asp and ...\asp\interaction\Cancel_JScript.asp.