HttpResponse.IsClientConnected 属性

定义

获取一个值,通过该值指示客户端是否仍连接在服务器上。

public:
 property bool IsClientConnected { bool get(); };
public bool IsClientConnected { get; }
member this.IsClientConnected : bool
Public ReadOnly Property IsClientConnected As Boolean

属性值

Boolean

如果客户端当前仍在连接,则为 true;否则为 false

示例

以下示例使用 IsClientConnected 该属性检查请求页面的客户端是否仍连接到服务器。 如果 IsClientConnected 为 true,代码将调用 Redirect 该方法,客户端将查看另一页。 如果 IsClientConnected 为 false,则代码调用 End 该方法并终止所有页面处理。

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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);
        }
        else
        {
            // If the browser is not connected
            // stop all response processing.
            Response.End();
        }
    }

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Private Sub Page_Load(sender As Object, e As EventArgs)

        ' Check whether the browser remains
        ' connected to the server.
        If (Response.IsClientConnected) Then

            ' If still connected, redirect
            ' to another page.             
            Response.Redirect("Page2VB.aspx", false)
        Else
            ' If the browser is not connected
            ' stop all response processing.
            Response.End()
        End If
    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>

注解

当以下条件为 true 时,属性 IsClientConnected 返回 false

适用于