共用方式為


ViewStateException.Referer 屬性

定義

取得頁面的 URL,這個頁面連結到發生檢視狀態例外狀況的頁面。

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

屬性值

包含 HTTP 參考項的 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_REFERER 屬性中 ServerVariables 變數相同的值。 如果先前沒有連結至頁面的要求,此值會是空字串 (「」) 。

適用於