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 使用已設定的資料驗證演算法。 三重 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