ViewStateException.IsConnected Eigenschaft

Definition

Ruft einen Wert ab, der angibt, ob der Client gegenwärtig mit dem Server verbunden ist.

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

Eigenschaftswert

true, wenn der Client noch mit dem Server verbunden ist, andernfalls false.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie eine Methode implementiert wird, die eine base64-codierte Zeichenfolge deserialisiert und eine ICollection Auflistung von Eigenschafteneinstellungen zurückgibt. Die Deserialize -Methode kann eine HttpException Ausnahme auslösen, die ein ViewStateException Objekt als innere Ausnahme enthält. Das Beispiel zeigt, wie Sie eine HttpException Ausnahme abfangen und die Eigenschaften aus dem ViewStateException -Objekt abrufen können.

private ICollection LoadControlProperties(string serializedProperties)
{

    ICollection controlProperties = null;

    // Create an ObjectStateFormatter to deserialize the properties.
    ObjectStateFormatter formatter = new ObjectStateFormatter();

    try
    {
        // Call the Deserialize method.
        controlProperties = (ArrayList)formatter.Deserialize(serializedProperties);
    }
    catch (HttpException e)
    {
        ViewStateException vse = (ViewStateException)e.InnerException;
        String logMessage;

        logMessage = "ViewStateException. Path: " + vse.Path + Environment.NewLine;
        logMessage += "PersistedState: " + vse.PersistedState + Environment.NewLine;
        logMessage += "Referer: " + vse.Referer + Environment.NewLine;
        logMessage += "UserAgent: " + vse.UserAgent + Environment.NewLine;

        LogEvent(logMessage);

        if (vse.IsConnected)
        {
            HttpContext.Current.Response.Redirect("ErrorPage.aspx");
        }
        else
        {
            throw e;
        }
    }
    return controlProperties;
}
Private Function LoadControlProperties(ByVal serializedProperties As String) As ICollection

    Dim controlProperties As ICollection = Nothing

    ' Create an ObjectStateFormatter to deserialize the properties.
    Dim formatter As New ObjectStateFormatter()

    Try
        ' Call the Deserialize method.
        controlProperties = CType(formatter.Deserialize(serializedProperties), ArrayList)
    Catch e As HttpException
        Dim vse As ViewStateException
        Dim logMessage As String

        vse = e.InnerException

        logMessage = "ViewStateException. Path: " + vse.Path + Environment.NewLine
        logMessage += "PersistedState: " + vse.PersistedState + Environment.NewLine
        logMessage += "Referer: " + vse.Referer + Environment.NewLine
        logMessage += "UserAgent: " + vse.UserAgent + Environment.NewLine

        LogEvent(logMessage)

        If (vse.IsConnected) Then
            HttpContext.Current.Response.Redirect("ErrorPage.aspx")
        Else
            Throw e
        End If
    End Try
    Return controlProperties
End Function 'LoadControlProperties

Hinweise

Diese Eigenschaft gibt denselben Wert wie das Aufrufen der IsClientConnected Eigenschaft zurück.

Gilt für:

Weitere Informationen