共用方式為


ViewStateException.IsConnected 屬性

定義

取得值,指出用戶端目前是否與伺服器連接著。

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

屬性值

如果用戶端仍然與伺服器連接著,則為 true,否則為 false

範例

下列程式碼範例示範如何實作方法,以還原序列化 base64 編碼字串,並傳 ICollection 回屬性設定的集合。 方法 Deserialize 可以擲回 HttpException 包含 物件做為內部例外狀況的例外 ViewStateException 狀況。 此範例示範如何攔截 HttpException 例外狀況,並從 物件擷 ViewStateException 取屬性。

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

備註

這個屬性會傳回與呼叫 IsClientConnected 屬性相同的值。

適用於

另請參閱