共用方式為


MachineKeySection.DecryptionKey 屬性

定義

取得或設定用來加密和解密資料的金鑰,或是產生金鑰的處理序。

public:
 property System::String ^ DecryptionKey { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter(typeof(System.Configuration.WhiteSpaceTrimStringConverter))]
[System.Configuration.ConfigurationProperty("decryptionKey", DefaultValue="AutoGenerate,IsolateApps")]
[System.Configuration.StringValidator(MinLength=1)]
public string DecryptionKey { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Configuration.WhiteSpaceTrimStringConverter))>]
[<System.Configuration.ConfigurationProperty("decryptionKey", DefaultValue="AutoGenerate,IsolateApps")>]
[<System.Configuration.StringValidator(MinLength=1)>]
member this.DecryptionKey : string with get, set
Public Property DecryptionKey As String

屬性值

String

金鑰值,或是表示如何產生金鑰的值。 預設為 "AutoGenerate,IsolateApps"。

屬性

範例

下列範例示範如何使用程式碼來設定 DecryptionKey 屬性。 這個範例是提供給 類別之較大範例的 MachineKeySection 一部分。

// Display DecryptionKey property.
Console.WriteLine("DecryptionKey: {0}",
  configSection.DecryptionKey);
' Display DecryptionKey property.
Console.WriteLine("DecryptionKey: {0}", configSection.DecryptionKey)

備註

屬性 DecryptionKey 用於加密和解密,例如在Windows Forms驗證中,以及當屬性設定為 「3DES」 或 「AES」 時的 Validation 檢視狀態。

使用 [自動產生] 選項可指定 ASP.NET 產生隨機金鑰,並將它儲存在本機安全性授權單位中。 [自動產生] 選項是預設值的一部分。

如果您將 「IsolateApps」 修飾詞新增至 「AutoGenerate」 ValidationKey 值,ASP.NET 使用每個應用程式的 AppDomainAppVirtualPath 產生唯一的加密金鑰。 這是預設值。

如果您將 「IsolateByAppId」 修飾詞新增至 「AutoGenerate」 ValidationKey 值,ASP.NET 使用每個應用程式的 AppDomainAppId 產生唯一的加密金鑰。 如果兩個不同的應用程式共用虛擬路徑 (可能是因為這些應用程式在不同的埠上執行) ,則此旗標可用來進一步區分它們彼此。 只有 ASP.NET 4.5 才能瞭解 「IsolateByAppId」 旗標,但不論 MachineKeySection.CompatibilityMode 設定為何,都可以使用它。

如果您需要在 Web 服務器陣列) (網路支援設定,請手動設定 DecryptionKey 屬性以確保一致的設定。 如需如何手動產生屬性值 DecryptionKey 的資訊,請參閱How To: Configure MachineKey in ASP.NET 2.0

這個屬性通常會以宣告方式在 Web.config 檔案之machineKey元素的 屬性中 DecryptionKey 設定。 如需詳細資訊,請參閱 machineKey 元素。

適用於

另請參閱