FormsAuthenticationConfiguration.Protection 属性

定义

获取或设置用于加密 Cookie 的加密类型。Gets or sets the encryption type used to encrypt the 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=Mono.Cecil.CustomAttributeArgument)]
public System.Web.Configuration.FormsProtectionEnum Protection { get; set; }
[<System.Configuration.ConfigurationProperty("protection", DefaultValue=Mono.Cecil.CustomAttributeArgument)>]
member this.Protection : System.Web.Configuration.FormsProtectionEnum with get, set
Public Property Protection As FormsProtectionEnum

属性值

FormsProtectionEnum

FormsProtectionEnum 枚举值之一。One of the FormsProtectionEnum enumeration values. 默认值是 AllThe default value is All.

注意 如果希望数据验证和加密来帮助保护 cookie,请确保使用此属性的默认值。Note Be sure to use the default value for this property if you want both data validation and encryption to help protect the cookie. 此选项使用已配置的数据验证算法(基于 machineKey)。This option uses the configured data-validation algorithm based on the machineKey. 如果三重 DES (3DES) 可用并且密钥足够长(48 字节或更长),则使用 3DES 来进行加密。Triple-DES (3DES) is used for encryption, if available and if the key is long enough (48 bytes or more).

若要增强对 Cookie 的保护,您还可以将 RequireSSL 设置为 trueTo improve the protection of your cookie, you may also want to set the RequireSSL to true.

属性

示例

下面的代码示例演示如何访问 Protection 属性。The following code example shows how to access the Protection property. 请参阅类主题中的代码示例 FormsAuthenticationConfiguration ,了解如何获取部分。Refer to the code example in the FormsAuthenticationConfiguration class topic to learn how to get the section.

// 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

适用于