ViewStateException Clase
Definición
Representa la excepción que se produce cuando el estado de vista no se puede cargar ni validar.Represents the exception that is thrown when the view state cannot be loaded or validated. Esta clase no puede heredarse.This class cannot be inherited.
public ref class ViewStateException sealed : Exception
[System.Serializable]
public sealed class ViewStateException : Exception
[<System.Serializable>]
type ViewStateException = class
inherit Exception
interface ISerializable
Public NotInheritable Class ViewStateException
Inherits Exception
- Herencia
- Atributos
- Implementaciones
Ejemplos
En el ejemplo de código siguiente se muestra cómo implementar un método que deserializa una cadena codificada en Base64 y devuelve una ICollection colección de valores de propiedad.The following code example demonstrates how to implement a method that deserializes a base64-encoded string and returns an ICollection collection of property settings. El Deserialize método puede producir una HttpException excepción que contenga un ViewStateException objeto como excepción interna.The Deserialize method can throw an HttpException exception that contains a ViewStateException object as an inner exception. En el ejemplo se muestra cómo se puede detectar una HttpException excepción y recuperar las propiedades del ViewStateException objeto.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
Comentarios
Si se produce una excepción cuando la página carga la información de estado de vista, la página crea un ViewStateException objeto y lo pasa como una excepción interna dentro de una HttpException excepción.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. La HttpException excepción se vuelve a iniciar para ser administrada por la aplicación.The HttpException exception is re-thrown to be handled by the application.
La ViewStateException clase almacena información sobre la excepción en la Message propiedad.The ViewStateException class stores information about the exception in the Message property. Si la solicitud tiene permiso de acceso a la ServerVariables propiedad, la Message propiedad contiene los valores devueltos por las RemoteAddress RemotePort propiedades,,,, UserAgent PersistedState Referer y Path ; de lo contrario, la Message propiedad contiene un mensaje de error genérico de estado de vista.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.
Una excepción de estado de vista puede ser el resultado de un error de validación de códigos de autenticación de mensajes (MAC).A view-state exception can be the result of a Message Authentication Codes (MAC) validation error. Si el atributo de página enableViewStateMac
se establece en true
, la información de estado de vista se codifica con un identificador de Mac.If the page attribute enableViewStateMac
is set to true
, view-state information is encoded with a MAC identifier. Cuando la información de estado de vista se devuelve al servidor, la página comprueba la codificación para asegurarse de que el usuario no la ha modificado.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. Si la página no puede validar la codificación MAC en la información de estado de vista, producirá una HttpException excepción con el ViewStateException objeto como excepción interna.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.
Para que la validación de MAC se realice correctamente, se debe aplicar un algoritmo hash a la información de estado de vista con la misma clave cuando se envía y recibe.For MAC validation to succeed, the view-state information must be hashed by the same key when it is sent and received. Dentro de una granja de servidores Web, la clave de equipo de cada servidor debe establecerse en una clave común.Within a Web farm, the machine key on each server should be set to a common key.
Constructores
ViewStateException() |
Inicializa una nueva instancia de la clase ViewStateException.Initializes a new instance of the ViewStateException class. |
Propiedades
Data |
Obtiene una colección de pares clave/valor que proporciona información definida por el usuario adicional sobre la excepción.Gets a collection of key/value pairs that provide additional user-defined information about the exception. (Heredado de Exception) |
HelpLink |
Obtiene o establece un vínculo al archivo de ayuda asociado a esta excepción.Gets or sets a link to the help file associated with this exception. (Heredado de Exception) |
HResult |
Obtiene o establece HRESULT, un valor numérico codificado que se asigna a una excepción específica.Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception. (Heredado de Exception) |
InnerException |
Obtiene la instancia Exception que produjo la excepción actual.Gets the Exception instance that caused the current exception. (Heredado de Exception) |
IsConnected |
Obtiene un valor que indica si el cliente está conectado al servidor actualmente.Gets a value indicating whether the client is currently connected to the server. |
Message |
Obtiene información de depuración sobre la solicitud HTTP que produjo una excepción del estado de vista.Gets debugging information about the HTTP request that resulted in a view-state exception. |
Path |
Obtiene la ruta de acceso de la solicitud HTTP que produjo una excepción del estado de vista.Gets the path of the HTTP request that resulted in a view-state exception. |
PersistedState |
Obtiene el contenido de la cadena del estado de vista que, al leerse, produjo la excepción del estado de vista.Gets the contents of the view-state string that, when read, caused the view-state exception. |
Referer |
Obtiene la dirección URL de la página vinculada a la página en la que se produjo la excepción del estado de vista.Gets the URL of the page that linked to the page where the view-state exception occurred. |
RemoteAddress |
Obtiene la dirección IP de la solicitud HTTP que produjo una excepción del estado de vista.Gets the IP address of the HTTP request that resulted in a view-state exception. |
RemotePort |
Obtiene el número de puerto de la solicitud HTTP que produjo una excepción del estado de vista.Gets the port number of the HTTP request that resulted in a view-state exception. |
Source |
Devuelve o establece el nombre de la aplicación o del objeto que generó el error.Gets or sets the name of the application or the object that causes the error. (Heredado de Exception) |
StackTrace |
Obtiene una representación de cadena de los marcos inmediatos en la pila de llamadas.Gets a string representation of the immediate frames on the call stack. (Heredado de Exception) |
TargetSite |
Obtiene el método que produjo la excepción actual.Gets the method that throws the current exception. (Heredado de Exception) |
UserAgent |
Obtiene el tipo de explorador de la solicitud HTTP que produjo una excepción del estado de vista.Gets the browser type of the HTTP request that resulted in a view-state exception. |
Métodos
Equals(Object) |
Determina si el objeto especificado es igual que el objeto actual.Determines whether the specified object is equal to the current object. (Heredado de Object) |
GetBaseException() |
Cuando se invalida en una clase derivada, devuelve la clase Exception que representa la causa principal de una o más excepciones posteriores.When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions. (Heredado de Exception) |
GetHashCode() |
Sirve como la función hash predeterminada.Serves as the default hash function. (Heredado de Object) |
GetObjectData(SerializationInfo, StreamingContext) |
Inicializa una nueva instancia de la clase ViewStateException con datos serializados.Initializes a new instance of the ViewStateException class with serialized data. |
GetType() |
Obtiene el tipo de tiempo de ejecución de la instancia actual.Gets the runtime type of the current instance. (Heredado de Exception) |
MemberwiseClone() |
Crea una copia superficial del Object actual.Creates a shallow copy of the current Object. (Heredado de Object) |
ToString() |
Crea y devuelve una representación de cadena de la excepción actual.Creates and returns a string representation of the current exception. (Heredado de Exception) |
Eventos
SerializeObjectState |
Ocurre cuando una excepción se serializa para crear un objeto de estado de excepción que contenga datos serializados sobre la excepción.Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception. (Heredado de Exception) |