PagesSection.EnableViewStateMac 属性

定义

获取或设置一个值,该值指定在从客户端回发页面时,ASP.NET 是否应在页面的视图状态上运行消息身份验证代码(MAC)。

public:
 property bool EnableViewStateMac { bool get(); void set(bool value); };
[System.Configuration.ConfigurationProperty("enableViewStateMac", DefaultValue=true)]
public bool EnableViewStateMac { get; set; }
[<System.Configuration.ConfigurationProperty("enableViewStateMac", DefaultValue=true)>]
member this.EnableViewStateMac : bool with get, set
Public Property EnableViewStateMac As Boolean

属性值

true 如果 ASP.NET 应在页面的视图状态上运行消息身份验证代码(MAC),则从客户端回发页面;否则,为 false. 默认值为 true

属性

示例

下面的代码示例演示如何使用该 EnableViewStateMac 属性。

// Get the current EnableViewStateMac property value.
Console.WriteLine(
    "Current EnableViewStateMac value: '{0}'",
    pagesSection.EnableViewStateMac);

// Set the EnableViewStateMac property to true.
pagesSection.EnableViewStateMac = true;
' Get the current EnableViewStateMac property value.
Console.WriteLine( _
    "Current EnableViewStateMac value: '{0}'", _
    pagesSection.EnableViewStateMac)

' Set the EnableViewStateMac property to true.
pagesSection.EnableViewStateMac = True

注解

视图状态 MAC 是隐藏变量的加密版本,当页面发送到浏览器时,页面的视图状态将保留到该变量。 如果此属性设置为 true,则会检查加密的视图状态,以验证它是否已在客户端上被篡改。

重要

即使应用程序或页面不使用视图状态,也不应在生产网站中设置 false 此属性。 除了视图状态之外,视图状态 MAC 还有助于确保其他 ASP.NET 函数的安全性。

适用于