HttpResponse.IsClientConnected Eigenschaft
Definition
Ruft einen Wert ab, der angibt, ob der Client noch mit dem Server verbunden ist.Gets a value indicating whether the client is still connected to the server.
public:
property bool IsClientConnected { bool get(); };
public bool IsClientConnected { get; }
member this.IsClientConnected : bool
Public ReadOnly Property IsClientConnected As Boolean
Eigenschaftswert
true
, wenn der Client gegenwärtig mit dem Server verbunden ist, andernfalls false
.true
if the client is currently connected; otherwise, false
.
Beispiele
Im folgenden Beispiel wird die IsClientConnected -Eigenschaft verwendet, um zu überprüfen, ob der Client, der die Seite anfordert, mit dem Server verbunden bleibt.The following example uses the IsClientConnected property to check whether the client that is requesting the page remains connected to the server. Wenn IsClientConnected den Wert true hat, ruft der Redirect Code die-Methode auf, und der Client zeigt eine andere Seite an.If IsClientConnected is true, the code calls the Redirect method, and the client will view another page. Wenn IsClientConnected false ist, ruft der Code die End -Methode auf, und die gesamte Seiten Verarbeitung wird beendet.If IsClientConnected is false, then 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"
"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>
Hinweise
Die IsClientConnected -Eigenschaft false
gibt zurück, wenn die folgenden Bedingungen zutreffen:The IsClientConnected property returns false
when the following conditions are true:
Die Verbindung mit dem Client wurde beendet.The connection to the client was terminated. Dies kann vorkommen, wenn Close die-Methode aufgerufen wurde, oder wenn der Client die Ausführung der Webseite beendet oder zu einer anderen Seite durchsucht hat.This can occur if the Close method was invoked, or if the client stopped execution of the Web page or browsed to another page.
Das HttpWorkerRequest Objekt, das die Anforderung verarbeitet,
null
ist, HttpWorkerRequest.IsClientConnected oder diefalse
Methode gibt zurück.The HttpWorkerRequest object that is handling the request isnull
or the HttpWorkerRequest.IsClientConnected method returnsfalse
. Wenn ein Benutzer HttpWorkerRequest definiertes-Objekt die Anforderung verarbeitet HttpWorkerRequest.IsClientConnected , kann die-Methode basierend auf benutzerdefinierten Kriterien festgelegt werden.If a custom HttpWorkerRequest object handles the request, then the HttpWorkerRequest.IsClientConnected method might be set based on custom criteria. Beispielsweise kann die benutzerdefinierte Workeranforderung ein Timeout nach einem bestimmten Zeitraum erzwingen.For example, the custom worker request might force a time-out after a period of time.