HttpResponse.IsClientConnected Property

Gets a value indicating whether the client is still connected to the server.

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

public bool IsClientConnected { get; }
/** @property */
public boolean get_IsClientConnected ()

public function get IsClientConnected () : boolean

Not applicable.

Property Value

true if the client is currently connected; otherwise, false.

The IsClientConnected property returns false under the following conditions:

  • The connection to the client was terminated. This can occur if the Close method was invoked or the client stopped execution of the Web page or browsed to another page.

  • The HttpWorkerRequest object that is handling the request is a null reference (Nothing in Visual Basic) or the HttpWorkerRequest.IsClientConnected method returns false. If a custom HttpWorkerRequest object handles the request, then the HttpWorkerRequest.IsClientConnected method might be set based on custom criteria. For example, the custom worker request might force a time-out after a period of time.

The following code example uses the IsClientConnected property to check whether the client requesting the page remains connected to the server. If IsClientConnected is true, the code calls the Redirect method, and the client will view another page. If IsClientConnected is false, the code calls the End method and all page processing is terminated.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

    private void Page_Load(object sender, EventArgs e)
        // Check whether the browser remains
        // connected to the server.
        if (Response.IsClientConnected)
            // If still connected, redirect
            // to another page. 
            Response.Redirect("Page2CS.aspx", false);
            // If the browser is not connected
            // stop all response processing.

<html xmlns="" >
    <title>ASP.NET Example</title>
    <form id="form1" runat="server">

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions