MachineKeySection.DecryptionKey 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置用于加密和解密数据的密钥,或密钥的生成过程。
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
属性值
键值或指示如何生成密钥的值。 默认值为“AutoGenerate,IsolateApps”。
- 属性
示例
以下示例演示如何使用代码设置 DecryptionKey 属性。 此示例是MachineKeySection类所提供的一个大型示例的一部分。
// Display DecryptionKey property.
Console.WriteLine("DecryptionKey: {0}",
configSection.DecryptionKey);
' Display DecryptionKey property.
Console.WriteLine("DecryptionKey: {0}", configSection.DecryptionKey)
注解
该 DecryptionKey 属性用于加密和解密,例如在 Windows 窗体身份验证中,以及属性 Validation 设置为“3DES”或“AES”时的视图状态。
使用“自动生成”选项指定 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 元素。