次の方法で共有


HttpResponse.IsClientConnected プロパティ

クライアントがサーバーにまだ接続されているかどうかを示す値を取得します。

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Public ReadOnly Property IsClientConnected As Boolean
'使用
Dim instance As HttpResponse
Dim value As Boolean

value = instance.IsClientConnected
public bool IsClientConnected { get; }
public:
property bool IsClientConnected {
    bool get ();
}
/** @property */
public boolean get_IsClientConnected ()
public function get IsClientConnected () : boolean
適用できません。

プロパティ値

クライアントが現在接続されている場合は true。それ以外の場合は false

解説

IsClientConnected プロパティは、次の条件で false を返します。

  • クライアントへの接続が終了した場合。これは、Close メソッドが呼び出された場合、またはクライアントが Web ページの実行を中止したか別のページを参照した場合に発生することがあります。

  • 要求を処理している HttpWorkerRequest オブジェクトが null 参照 (Visual Basic では Nothing) であるか、HttpWorkerRequest.IsClientConnected メソッドが false を返す場合。カスタム HttpWorkerRequest オブジェクトが要求を処理する場合、HttpWorkerRequest.IsClientConnected メソッドは、独自の条件に基づいて設定されることがあります。たとえば、カスタムのワーカー要求により、一定期間の経過後にタイムアウトを強制的に実行する場合があります。

使用例

次のコード例では、IsClientConnected プロパティを使用して、ページを要求しているクライアントがサーバーにまだ接続されているかどうかを確認します。IsClientConnected が true の場合、Redirect メソッドが呼び出され、クライアントに別のページが表示されます。IsClientConnected が false の場合、End メソッドが呼び出され、すべてのページの処理が終了します。

<%@ 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>
<%@ 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>

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

HttpResponse クラス
HttpResponse メンバ
System.Web 名前空間