ViewStateException.IsConnected 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个值,该值指示客户端当前是否连接在服务器上。
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 属性相同的值。