HttpCapabilitiesBase.RequiresSpecialViewStateEncoding 屬性

定義

取得值,指出瀏覽器是否需要對 VIEWSTATE 值進行特殊編碼。

public:
 virtual property bool RequiresSpecialViewStateEncoding { bool get(); };
public virtual bool RequiresSpecialViewStateEncoding { get; }
member this.RequiresSpecialViewStateEncoding : bool
Public Overridable ReadOnly Property RequiresSpecialViewStateEncoding As Boolean

屬性值

Boolean

如果瀏覽器需要對 true 值進行特殊編碼,則為 VIEWSTATE,否則為 false。 預設為 false

範例

下列程式碼範例示範如何判斷瀏覽器 VIEWSTATE 是否需要特別編碼的值。

<%@ page language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    void Page_Load(Object Sender, EventArgs e)
    {
        CheckBrowserCaps();
    }

    void CheckBrowserCaps()
    {
        String labelText = "";
        System.Web.HttpBrowserCapabilities myBrowserCaps = Request.Browser;
        if (((System.Web.Configuration.HttpCapabilitiesBase)myBrowserCaps).RequiresSpecialViewStateEncoding)
        {
            labelText = "Browser requires view state values to be specially encoded.";
        }
        else
        {
            labelText = "Browser does not require view state values to be specially encoded.";
        }

        Label1.Text = labelText;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Browser Capabilities Sample</title>
</head>
<body>
    <form runat="server" id="form1">
        <div>
            Browser Capabilities:
            <p/><asp:Label ID="Label1" Runat="server" />
        </div>
    </form>
</body>
</html>
<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        CheckBrowserCaps()
    End Sub

    Function CheckBrowserCaps()

        Dim labelText As String = ""
        Dim myBrowserCaps As System.Web.HttpBrowserCapabilities = Request.Browser
        If (CType(myBrowserCaps, System.Web.Configuration.HttpCapabilitiesBase)).RequiresSpecialViewStateEncoding Then
            labelText = "Browser requires view state values to be specially encoded."
        Else
            labelText = "Browser does not require view state values to be specially encoded."
        End If

        Label1.Text = labelText

    End Function 'CheckBrowserCaps
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Browser Capabilities Sample</title>
</head>
<body>
    <form runat="server" id="form1">
        <div>
            Browser Capabilities:
            <p/><asp:Label ID="Label1" Runat="server" />
        </div>
    </form>
</body>
</html>

備註

HTTP 是無狀態通訊協定,而且 VIEWSTATE 是一種機制,用來保存多個要求之間的用戶端變更。 網頁上的每個控制項都包含 ViewState 屬性,代表用戶端所做的任何變更累積。 在Web Form頁面中,這些變更會在回傳資料中編碼為 value 具有 type 屬性 hidden 之 HTML <input> 專案的 。 例如:

<input type="hidden" name="__VIEWSTATE" value="t0PH_u56?cDxleHQ7P=" />  

如果 true 為 ,則瀏覽器不會正確傳送值中的 VIEWSTATE 非字母字元,也不會由中繼閘道傳送。 若要修正此問題,伺服器控制配接器會將 值中的 VIEWSTATE 非字母字元取代為不需要在 HTTP 要求中編碼的配接器。

適用於