HttpCapabilitiesBase.RequiresSpecialViewStateEncoding 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會得到一個值,表示瀏覽器是否需要 VIEWSTATE 特別編碼的值。
public:
virtual property bool RequiresSpecialViewStateEncoding { bool get(); };
public virtual bool RequiresSpecialViewStateEncoding { get; }
member this.RequiresSpecialViewStateEncoding : bool
Public Overridable ReadOnly Property RequiresSpecialViewStateEncoding As 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 屬性,代表用戶端所做的任何變更的累積。 在網頁表單頁面中,這些變更會以帶有type屬性為 hidden的 HTML <input> 元素的回傳資料value中編碼。 例如:
<input type="hidden" name="__VIEWSTATE" value="t0PH_u56?cDxleHQ7P=" />
若 true,則該值中的 VIEWSTATE 非字母字元將無法被瀏覽器或中介閘道正確傳送。 為了修正此問題,伺服器控制介面卡會將非字母字元替換為不需要 HTTP 請求編碼的字元 VIEWSTATE 。