FormsAuthenticationConfiguration.Protection 属性

定义

获取或设置用于加密 Cookie 的加密类型。

public:
 property System::Web::Configuration::FormsProtectionEnum Protection { System::Web::Configuration::FormsProtectionEnum get(); void set(System::Web::Configuration::FormsProtectionEnum value); };
[System.Configuration.ConfigurationProperty("protection", DefaultValue=System.Web.Configuration.FormsProtectionEnum.All)]
public System.Web.Configuration.FormsProtectionEnum Protection { get; set; }
[<System.Configuration.ConfigurationProperty("protection", DefaultValue=System.Web.Configuration.FormsProtectionEnum.All)>]
member this.Protection : System.Web.Configuration.FormsProtectionEnum with get, set
Public Property Protection As FormsProtectionEnum

属性值

FormsProtectionEnum

FormsProtectionEnum 枚举值之一。 默认值是 All

注意 如果希望数据验证和加密都有助于保护 Cookie,请务必使用此属性的默认值。 此选项使用已配置的数据验证算法(基于 machineKey)。 如果三重 DES (3DES) 可用并且密钥足够长(48 字节或更长),则使用 3DES 来进行加密。

若要增强对 Cookie 的保护,您还可以将 RequireSSL 设置为 true

属性

示例

下面的代码示例演示如何访问 Protection 属性。 请参阅类主题中的 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

适用于

另请参阅