FormsProtectionEnum 列舉

定義

定義要用於 Cookie 的加密類型,如果有的話。

public enum class FormsProtectionEnum
public enum FormsProtectionEnum
type FormsProtectionEnum = 
Public Enum FormsProtectionEnum
繼承
FormsProtectionEnum

欄位

名稱 Description
All 0

規定應用程式同時使用資料驗證與加密來協助保護 Cookie。 此選項使用配置的資料驗證演算法(基於元素)。machineKey Triple-DES(3DES)用於加密,前提是有且金鑰長度至少為 48 位元組。 All 是預設(且建議)的值。

None 1

規定對於僅用於個人化且安全性較低的網站,加密與驗證均被禁用。 不建議以此方式使用 Cookie;然而,這是使用 .NET 框架實現個人化最省資源的方式。

Encryption 2

規定 Cookie 使用 Triple-DES 或 DES 加密,但資料驗證不會對 Cookie 進行。 以這種方式使用的 Cookie 可能會遭受選擇性明文安全攻擊。

Validation 3

規定應用程式必須使用驗證機制來驗證加密 Cookie 的內容在傳輸過程中未被更改。 Cookie 是透過將驗證金鑰與 Cookie 資料串接,計算訊息認證碼(MAC),並將 MAC 附加到發出的 Cookie 上來建立的。

範例

以下範例展示了如何使用 FormsProtectionEnum 枚舉。 參考課堂上的 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

備註

如果你選擇該值, All 系統會根據 machineKey 標籤使用已設定的資料驗證演算法。 這是預設且建議的數值。

如果您選擇 None,cookies 可能會遭受明文攻擊。

如果你選擇 Validation,Cookie 會透過 Cookie 驗證建立,方法是將驗證金鑰與 Cookie 資料串接,計算訊息驗證碼(MAC),並將 MAC 附加到發出的 cookie 上。

適用於

另請參閱