HttpResponse.IsClientConnected Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene un valore che indica se il client è ancora connesso al server.
public:
property bool IsClientConnected { bool get(); };
public bool IsClientConnected { get; }
member this.IsClientConnected : bool
Public ReadOnly Property IsClientConnected As Boolean
Valore della proprietà
true se il client è attualmente connesso; in caso contrario, false.
Esempio
Nell'esempio seguente viene utilizzata la IsClientConnected proprietà per verificare se il client che richiede la pagina rimane connesso al server. Se IsClientConnected è true, il codice chiama il Redirect metodo e il client visualizzerà un'altra pagina. Se IsClientConnected è false, il codice chiama il End metodo e l'elaborazione di tutte le pagine viene terminata.
<%@ 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>
Commenti
La IsClientConnected proprietà restituisce false quando le condizioni seguenti sono vere:
La connessione al client è stata terminata. Ciò può verificarsi se il Close metodo è stato richiamato o se il client ha interrotto l'esecuzione della pagina Web o se è stata visualizzata un'altra pagina.
L'oggetto HttpWorkerRequest che gestisce la richiesta è
nullo il HttpWorkerRequest.IsClientConnected metodo restituiscefalse. Se un oggetto personalizzato HttpWorkerRequest gestisce la richiesta, il HttpWorkerRequest.IsClientConnected metodo potrebbe essere impostato in base a criteri personalizzati. Ad esempio, la richiesta di lavoro personalizzata potrebbe forzare un timeout dopo un periodo di tempo.