ViewStateException.UserAgent Propiedad

Definición

Obtiene el tipo de explorador de la solicitud HTTP que produjo una excepción del estado de vista.

public:
 property System::String ^ UserAgent { System::String ^ get(); };
public string UserAgent { get; }
member this.UserAgent : string
Public ReadOnly Property UserAgent As String

Valor de propiedad

Objeto String con el agente de usuario, que es normalmente el tipo de explorador.

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. El Deserialize método puede producir una HttpException excepción que contiene un ViewStateException objeto como una excepción interna. En el ejemplo se muestra cómo se puede detectar una HttpException excepción y recuperar las propiedades del ViewStateException objeto .

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

Esta propiedad devuelve el mismo valor que la HTTP_USER_AGENT variable de la ServerVariables propiedad .

Se aplica a