FormsProtectionEnum 枚举


定义要用于 Cookie 的加密类型(如果存在加密类型)。Defines the type of encryption, if any, to use for cookies.

public enum class FormsProtectionEnum
public enum FormsProtectionEnum
type FormsProtectionEnum = 
Public Enum FormsProtectionEnum


All 0

指定应用程序使用数据验证和加密来保护 Cookie。Specifies that the application use both data validation and encryption to help protect cookies. 此选项使用已配置的数据验证算法(基于 machineKey 元素)。This option uses the configured data-validation algorithm (based on the machineKey element). Triple-DES (3DES) 用于加密,条件是它可用且密钥长度至少为 48 个字节。Triple-DES (3DES) is used for encryption, if it is available and if the key is at least 48 bytes long. All 是默认(推荐)值。All is the default (and recommended) value.

Encryption 2

指定使用 Triple-DES 或 DES 加密 Cookie,但不对 Cookie 执行数据验证。Specifies that cookies are encrypted using Triple-DES or DES, but data validation is not performed on cookies. 以这种方式使用的 Cookie 可能会遭到所选择的明文安全性攻击。Cookies used this way might be subject to chosen plaintext security attacks.

None 1

指定对仅将 Cookie 用于个性化设置且安全要求较低的站点禁用加密和验证。Specifies that both encryption and validation are disabled for sites that use cookies only for personalization and thus have weaker security requirements. 建议不要以此方式使用 Cookie;但它对于使用 .NET Framework 实现个人化却是一种消耗资源程度最低的方法。Using cookies in this manner is not recommended; however, it is the least resource-intensive way to enable personalization using the .NET Framework.

Validation 3

指定该应用程序使用验证方案来验证已加密的 Cookie 的内容在传输中未被更改。Specifies that the application use a validation scheme to verify that the contents of an encrypted cookie have not been altered in transit. Cookie 的创建方式是:将验证密钥与 Cookie 数据连接在一起,计算消息身份验证代码 (MAC),然后将 MAC 追加到输出 Cookie 中。The cookie is created by concatenating a validation key with the cookie data, computing a Message Authentication Code (MAC), and appending the MAC to the outgoing cookie.


下面的示例演示如何使用FormsProtectionEnum枚举。The following example shows how to use the FormsProtectionEnum enumeration. 请参阅FormsAuthenticationConfiguration类中的代码示例, 了解如何获取部分。Refer to the code example in the FormsAuthenticationConfiguration class to learn how to get the section.

// Get the current Protection.
FormsProtectionEnum currentProtection = 

// Set the Protection property.
formsAuthentication.Protection = 

' Get the current Protection.
  Dim currentProtection As FormsProtectionEnum = _

' Set the Protection property.
formsAuthentication.Protection = FormsProtectionEnum.All


如果选择All值, 系统将根据machineKey标记使用已配置的数据验证算法。If you select the All value, the system uses the configured data-validation algorithm, based on the machineKey tag. 这是默认值和推荐的值。This is the default and recommended value.

如果选择None, cookie 可能会受到明文攻击。If you select None, cookies might be subject to plaintext attacks.

如果选择Validation此项, 则使用 cookie 验证来创建 cookie, 方法是: 将验证密钥与 cookie 数据连接, 计算消息验证代码 (MAC), 并将 MAC 追加到传出 cookie。If you select Validation, the cookie is created using cookie validation by concatenating a validation key with the cookie data, computing a Message Authentication Code (MAC), and appending the MAC to the outgoing cookie.