FormsProtectionEnum 枚举

定义

定义用于 Cookie 的加密类型(如果有)。

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

字段

名称 说明
All 0

指定应用程序同时使用数据验证和加密来帮助保护 Cookie。 此选项使用配置的数据验证算法(基于 machineKey 元素)。 Triple-DES(3DES)用于加密(如果可用),并且密钥长度至少为 48 字节。 All 是默认值(建议)。

None 1

指定对仅对个性化使用 Cookie 的网站禁用加密和验证,因此具有较弱的安全要求。 不建议以这种方式使用 Cookie;但是,使用 .NET Framework 启用个性化是资源密集型最少的方法。

Encryption 2

指定使用 Triple-DES 或 DES 加密 Cookie,但不会对 Cookie 执行数据验证。 以这种方式使用的 Cookie 可能会受到选择的纯文本安全攻击。

Validation 3

指定应用程序使用验证方案来验证加密 Cookie 的内容是否已在传输中更改。 Cookie 是通过将验证密钥与 Cookie 数据连接、计算消息身份验证代码(MAC)以及将 MAC 追加到传出 Cookie 来创建的。

示例

以下示例演示如何使用 FormsProtectionEnum 枚举。 请参阅类中的 FormsAuthenticationConfiguration 代码示例,了解如何获取该部分。

// Get the current Protection.
FormsProtectionEnum currentProtection =
    formsAuthentication.Protection;

// Set the Protection property.
formsAuthentication.Protection =
    FormsProtectionEnum.All;
' Get the current Protection.
Dim currentProtection As FormsProtectionEnum =
formsAuthentication.Protection

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

注解

如果选择 All 该值,系统会根据 machineKey 标记使用配置的数据验证算法。 这是默认值和建议值。

如果选择 None,Cookie 可能会受到纯文本攻击。

如果选择 Validation,则会使用 Cookie 验证创建 Cookie 验证,方法是将验证密钥与 Cookie 数据连接,计算消息身份验证代码(MAC),并将 MAC 追加到传出 Cookie。

适用于

另请参阅