YouTip LogoYouTip

Prop Isclientconnected

## ASP IsClientConnected Property The `IsClientConnected` property is a read-only property of the ASP `Response` object. It indicates whether the client (browser) has disconnected from the server since the last `Response.Write` occurred. This property is highly useful for optimizing server-side performance. If a client disconnects (for example, by closing the browser window or clicking the "Stop" button) while the server is processing a long-running script, you can use `IsClientConnected` to halt execution and save valuable server resources. --- ### Syntax ```vbscript Response.IsClientConnected ``` ### Return Values * **`True`**: The client is still connected to the server. * **`False`**: The client has disconnected from the server. --- ### Code Examples #### Basic Usage The following example checks if the client is still connected and displays a message accordingly: ```asp <% If Response.IsClientConnected = True Then Response.Write("The user is still connected!") Else ' Note: In a real-world scenario, if the client is disconnected, ' writing to the response will not be visible to the user. Response.Write("The user is not connected!") End If %> ``` #### Real-World Scenario: Optimizing Long-Running Queries In a production environment, `IsClientConnected` is typically used to abort expensive operations (like large database queries or complex loops) if the user has navigated away from the page. ```asp <% ' Loop simulating a time-consuming process For i = 1 To 10000 ' Perform a portion of the heavy task here ' Check if the client is still waiting for the response If Not Response.IsClientConnected Then ' Clean up resources and terminate script execution to save server CPU Session.Abandon() Response.End() End If Next %> ``` --- ### Important Considerations 1. **IIS Buffering**: If ASP buffering is enabled (`Response.Buffer = True`), the server does not send data to the client until the entire script finishes or `Response.Flush` is called. Because `IsClientConnected` relies on network traffic to detect a disconnection, it may not return `False` accurately unless you periodically flush the buffer using `Response.Flush`. 2. **Network Latency**: There can be a slight delay between the moment a user disconnects and the moment the server detects it. It is best practice to use this property before starting major blocks of processing within a loop.
← Prop PicsProp Expiresabsolute β†’