FormsAuthenticationConfiguration.Protection 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定用於加密 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的設定資料驗證演算法。 Triple-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