Share via


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 列舉值。 預設值是 All

注意 如果您想要資料驗證和加密來協助保護 Cookie,請務必使用此屬性的預設值。 這個選項會根據 machineKey 使用已設定的資料驗證演算法。 三重 DES (3DES) 用於加密,如果可用且金鑰夠長 (48 個位元組以上)。

若要提高 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

適用於

另請參閱