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 Forms页中,这些更改在回发数据中编码为value具有type属性的 hiddenHTML <input> 元素。 例如:

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

如果 true值中的 VIEWSTATE 非字母字符不会由浏览器正确发送,也不会由中间网关发送。 若要更正此问题,服务器控制适配器会将值中的 VIEWSTATE 非字母字符替换为不需要在 HTTP 请求中编码的字符。

适用于