ViewStateException.UserAgent 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取导致视图状态异常的 HTTP 请求的浏览器类型。
public:
property System::String ^ UserAgent { System::String ^ get(); };
public string UserAgent { get; }
member this.UserAgent : string
Public ReadOnly Property UserAgent As String
属性值
一个 String,其中包含用户代理(通常为浏览器类型)。
示例
下面的代码示例演示如何实现一个方法,该方法反序列化 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
注解
此属性返回与 属性中的 HTTP_USER_AGENT
ServerVariables 变量相同的值。