ViewStateException.Path 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得導致視圖狀態異常的 HTTP 請求路徑。
public:
property System::String ^ Path { System::String ^ get(); };
public string Path { get; }
member this.Path : string
Public ReadOnly Property Path As String
屬性值
String A 包含請求路徑。
範例
以下程式碼範例示範如何實作一種方法,將 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
備註
此屬性回傳與 PATH_INFO 屬性中的 ServerVariables 變數值相同。 它會回傳主機名稱後的路徑部分。 例如,在網址 http://www.contoso.com/virdir/page.html中,會 Path 回傳 /virdir/page.html。