MachineKeySection.ValidationKey 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定用於驗證表單認證與檢視狀態資料的金鑰,或是金鑰產生過程。
public:
property System::String ^ ValidationKey { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter(typeof(System.Configuration.WhiteSpaceTrimStringConverter))]
[System.Configuration.ConfigurationProperty("validationKey", DefaultValue="AutoGenerate,IsolateApps")]
[System.Configuration.StringValidator(MinLength=1)]
public string ValidationKey { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Configuration.WhiteSpaceTrimStringConverter))>]
[<System.Configuration.ConfigurationProperty("validationKey", DefaultValue="AutoGenerate,IsolateApps")>]
[<System.Configuration.StringValidator(MinLength=1)>]
member this.ValidationKey : string with get, set
Public Property ValidationKey As String
屬性值
一個鍵值,或表示鍵值如何產生的值。 預設是「自動生成,隔離應用程式」。
- 屬性
範例
以下範例展示了如何用程式碼設定該 ValidationKey 屬性。 此範例是本類別更大 MachineKeySection 範例的一部分。
// Display ValidationKey property.
Console.WriteLine("ValidationKey: {0}",
configSection.ValidationKey);
' Display ValidationKey property.
Console.WriteLine("ValidationKey: {0}", _
configSection.ValidationKey)
備註
ValidationKey當 enableViewStateMAC 建立true訊息認證碼(MAC)以使 ASP.NET 判斷視圖狀態是否被竄改時,會使用此特性。 此 ValidationKey 特性也用於產生程序外、應用程式專屬的會話 ID,以確保會話狀態變數在不同應用程式間被隔離。
使用「自動生成」選項指定 ASP.NET 產生隨機金鑰並將其儲存在地方安全管理局。 「自動生成」選項是預設值的一部分。
如果你在「AutoGenerate」 ValidationKey 值中加上「IsolateApps」修飾符,ASP.NET 會利用每個應用程式的 AppDomainAppVirtualPath。 這是預設設定。
如果你在「AutoGenerate」 ValidationKey 值中加上「IsolateByAppId」修飾符,ASP.NET 會利用每個應用程式的 AppDomainAppId。 如果兩個不同的應用程式共用虛擬路徑(可能因為它們在不同埠上運行),這個旗標可以用來進一步區分它們。 「IsolateByAppId」旗標僅能被 ASP.NET 4.5 理解,但無論設定為何 MachineKeySection.CompatibilityMode 都可以使用。
如果你需要支援跨網路伺服器(網路農場)的設定,請手動設定屬性 ValidationKey 以確保配置一致。 關於如何手動產生屬性值 DecryptionKey 的資訊,請參見 ASP.NET 2.0 中的 How To: Configure MachineKey。
此屬性通常以宣告式方式設定於 validationKey Web.config 檔案的 machineKey 元素屬性中。