Name

IsClientConnected

Synopsis

Boolean = Response.IsClientConnected

Returns a Boolean indicating whether the client is still connected. Returns False if the client is no longer connected.

Parameters

Boolean

A Boolean variable to receive the value of the property.

Example

The example checks the IsClientConnected property before starting a long-running processing task in order to avoid the expense of running the task if the client is no longer connected. If the property returns False, the code calls the Response.End method. Even though the client has disconnected and can no longer receive the buffered output (which is sent when the End method is called), calling the End method is still a good idea, since it will halt further processing of the page and fire the Application_EndRequest event. If you have written cleanup code for the page that is run by the event handler for Application_EndRequest, calling Response.End will ensure that the cleanup code is executed, even if the client disconnects.

Sub Page_Load(  )
   'Check client connection status
   If Response.IsClientConnected = False Then
      Response.End
   Else
      'Start long-running processing task
   End If
End Sub

Notes

The IsClientConnected property is especially useful for long-running processes that require a significant amount of processing resources on the server. By querying the IsClientConnected property before starting an expensive processing task, or by querying the property periodically during processing, you can bypass further processing ...

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.