ViewStateException ViewStateException ViewStateException ViewStateException Class

定義

表示當檢視狀態無法載入或驗證時所擲回的例外狀況。Represents the exception that is thrown when the view state cannot be loaded or validated. 這個類別無法被繼承。This class cannot be inherited.

public ref class ViewStateException sealed : Exception
[System.Serializable]
public sealed class ViewStateException : Exception
type ViewStateException = class
    inherit Exception
    interface ISerializable
Public NotInheritable Class ViewStateException
Inherits Exception
繼承
ViewStateExceptionViewStateExceptionViewStateExceptionViewStateException
屬性
實作

範例

下列程式碼範例示範如何實作的方法,將 base64 編碼的字串還原序列化,並傳回ICollection屬性設定的集合。The following code example demonstrates how to implement a method that deserializes a base64-encoded string and returns an ICollection collection of property settings. Deserialize方法會擲回HttpException例外狀況,其中包含ViewStateException物件做為內部例外狀況。The Deserialize method can throw an HttpException exception that contains a ViewStateException object as an inner exception. 此範例示範您可以攔截HttpException例外狀況,並擷取從屬性ViewStateException物件。The example shows how you can catch an HttpException exception and retrieve the properties from the ViewStateException object.

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   

備註

頁面載入的檢視狀態資訊的頁面時,就會發生的例外狀況,建立ViewStateException物件,並將它當做內部例外狀況內傳遞HttpException例外狀況。If an exception occurs when the page loads the view-state information, the page creates a ViewStateException object and passes it as an inner exception within an HttpException exception. HttpException例外狀況是由應用程式重新擲回。The HttpException exception is re-thrown to be handled by the application.

ViewStateException類別會儲存在例外狀況資訊Message屬性。The ViewStateException class stores information about the exception in the Message property. 如果要求具備存取權限ServerVariables屬性,則Message屬性包含傳回的值RemoteAddressRemotePortUserAgentPersistedStateReferer,以及Path[屬性],否則,Message屬性包含檢視狀態的一般錯誤訊息。If the request has permission to access the ServerVariables property, then the Message property contains the values returned from the RemoteAddress, RemotePort, UserAgent, PersistedState, Referer, and Path properties; otherwise, the Message property contains a generic view-state error message.

檢視狀態例外狀況可以是訊息驗證碼 (MAC) 驗證錯誤的結果。A view-state exception can be the result of a Message Authentication Codes (MAC) validation error. 如果頁面屬性enableViewStateMac設為true,檢視狀態資訊編碼與 MAC 的識別項。If the page attribute enableViewStateMac is set to true, view-state information is encoded with a MAC identifier. 當檢視狀態資訊回傳至伺服器時,頁面會驗證要確定,它未被改變使用者的編碼方式。When the view-state information is posted back to the server, the page verifies the encoding to ensure that it has not been altered by the user. 如果頁面無法驗證檢視狀態資訊編碼的 MAC,則會擲回HttpException例外狀況ViewStateException物件做為內部例外狀況。If the page cannot validate the MAC encoding on the view-state information, it will throw an HttpException exception with the ViewStateException object as an inner exception.

MAC 驗證成功,檢視狀態資訊必須是雜湊由相同的索引鍵時傳送和接收。For MAC validation to succeed, the view-state information must be hashed by the same key when it is sent and received. Web 伺服陣列中每一部伺服器上的電腦金鑰應該設定為相同的索引鍵。Within a Web farm, the machine key on each server should be set to a common key.

建構函式

ViewStateException() ViewStateException() ViewStateException() ViewStateException()

初始化 ViewStateException 類別的新執行個體。Initializes a new instance of the ViewStateException class.

屬性

Data Data Data Data

取得提供例外狀況之其他使用者定義相關資訊的索引鍵/值組集合。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Inherited from Exception)
HelpLink HelpLink HelpLink HelpLink

取得或設定與這個例外狀況相關聯的說明檔連結。Gets or sets a link to the help file associated with this exception.

(Inherited from Exception)
HResult HResult HResult HResult

取得或設定 HRESULT,它是指派給特定例外狀況的編碼數值。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException InnerException InnerException InnerException

取得造成目前例外狀況的 Exception 執行個體。Gets the Exception instance that caused the current exception.

(Inherited from Exception)
IsConnected IsConnected IsConnected IsConnected

取得值,指出用戶端目前是否與伺服器連接著。Gets a value indicating whether the client is currently connected to the server.

Message Message Message Message

取得造成檢視狀態例外狀況之 HTTP 要求的偵錯資訊。Gets debugging information about the HTTP request that resulted in a view-state exception.

Path Path Path Path

取得造成檢視狀態例外狀況之 HTTP 要求的路徑。Gets the path of the HTTP request that resulted in a view-state exception.

PersistedState PersistedState PersistedState PersistedState

取得當讀取時造成檢視狀態例外狀況之檢視狀態字串的內容。Gets the contents of the view-state string that, when read, caused the view-state exception.

Referer Referer Referer Referer

取得頁面的 URL,這個頁面連結到發生檢視狀態例外狀況的頁面。Gets the URL of the page that linked to the page where the view-state exception occurred.

RemoteAddress RemoteAddress RemoteAddress RemoteAddress

取得造成檢視狀態例外狀況之 HTTP 要求的 IP 位址。Gets the IP address of the HTTP request that resulted in a view-state exception.

RemotePort RemotePort RemotePort RemotePort

取得造成檢視狀態例外狀況之 HTTP 要求的通訊埠編號。Gets the port number of the HTTP request that resulted in a view-state exception.

Source Source Source Source

取得或設定造成錯誤的應用程式或物件的名稱。Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
StackTrace StackTrace StackTrace StackTrace

取得呼叫堆疊上即時運算框架的字串表示。Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
TargetSite TargetSite TargetSite TargetSite

取得擲回目前例外狀況的方法。Gets the method that throws the current exception.

(Inherited from Exception)
UserAgent UserAgent UserAgent UserAgent

取得造成檢視狀態例外狀況之 HTTP 要求的瀏覽器類型。Gets the browser type of the HTTP request that resulted in a view-state exception.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

在衍生類別中覆寫時,傳回一或多個後續的例外狀況的根本原因 ExceptionWhen overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

使用序列化資料,初始化 ViewStateException 類別的新執行個體。Initializes a new instance of the ViewStateException class with serialized data.

GetType() GetType() GetType() GetType()

取得目前執行個體的執行階段類型。Gets the runtime type of the current instance.

(Inherited from Exception)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

建立並傳回目前例外狀況的字串表示。Creates and returns a string representation of the current exception.

(Inherited from Exception)

事件

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

當例外狀況序列化,以建立包含例外狀況相關序列化資料的例外狀況狀態物件時,就會發生此事件。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

適用於

另請參閱