HttpResponse.IsClientConnected 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會取得一個值,表示用戶端是否仍連接伺服器。
public:
property bool IsClientConnected { bool get(); };
public bool IsClientConnected { get; }
member this.IsClientConnected : bool
Public ReadOnly Property IsClientConnected As Boolean
屬性值
true如果用戶端目前已連接;否則,。 false
範例
以下範例使用該 IsClientConnected 屬性來檢查請求該頁面的用戶端是否仍與伺服器連接。 若 IsClientConnected 為真,程式碼會呼叫該 Redirect 方法,客戶端將查看另一頁。 若 IsClientConnected 為假,則程式碼呼叫該 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>
備註
當以下條件成立時,該 IsClientConnected 屬性會返回 false :
與客戶端的連線被終止。 這種情況可能發生在方法 Close 被呼叫時,或是客戶端停止執行網頁或瀏覽到其他頁面時。
處理請求的 HttpWorkerRequest 物件是
null,或是 HttpWorkerRequest.IsClientConnected 方法回傳false。 如果是自訂 HttpWorkerRequest 物件處理請求,那麼方法 HttpWorkerRequest.IsClientConnected 可能會根據自訂條件設定。 例如,自訂工作者請求可能會在一段時間後強制暫停。