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 窗体身份验证中,以及属性设置为“3DES”或“AES”时的Validation视图状态。

使用“自动生成”选项指定 ASP.NET 生成随机密钥并将其存储在本地安全机构中。 “自动生成”选项是默认值的一部分。

如果将“IsolateApps”修饰符添加到“AutoGenerate”ValidationKey值,ASP.NET 使用每个AppDomainAppVirtualPath应用程序生成唯一的加密密钥。 这是默认设置。

如果将“IsolateByAppId”修饰符添加到“AutoGenerate”ValidationKey值,ASP.NET 通过使用每个AppDomainAppId应用程序的密钥为每个应用程序生成唯一的加密密钥。 如果两个不同的应用程序共享虚拟路径 (可能是因为这些应用程序在不同的端口上运行) ,则可以使用此标志来进一步区分它们彼此。 “IsolateByAppId”标志仅由 ASP.NET 4.5 理解,但无论设置如何MachineKeySection.CompatibilityMode,都可以使用它。

如果需要跨 Web 服务器网络支持配置 (Web 场) ,请手动设置 DecryptionKey 该属性以确保配置一致。 有关如何手动为属性生成值DecryptionKey的信息,请参阅 How To: Configure MachineKey in ASP.NET 2.0

此属性通常以声明方式在 Web.config 文件的 machineKey 元素的属性中DecryptionKey设置。 有关详细信息,请参阅 machineKey 元素。

适用于

另请参阅