共用方式為


MachineKeySection 類別

定義組態設定,以控制用於加密、解密和媒體存取控制的金鑰產生和演算法, (MAC) 表單驗證、檢視狀態驗證和會話狀態應用程式隔離中的作業。

Syntax

class MachineKeySection : ConfigurationSection  

方法

下表列出 類別所 MachineKeySection 公開的方法。

名稱 描述
GetAllowDefinition (繼承自 ConfigurationSection.)
GetAllowLocation (繼承自 ConfigurationSection。)
RevertToParent (繼承自 ConfigurationSection。)
SetAllowDefinition (繼承自 ConfigurationSection。)
SetAllowLocation (繼承自 ConfigurationSection。)

屬性

下表列出 類別所 MachineKeySection 公開的屬性。

名稱 描述
Decryption 讀取/寫入修剪 string 值,指定用來解密資料的雜湊演算法類型。 可能的值稍後會列在一節中。 預設值為 「Auto」。
DecryptionKey 讀取/寫入修剪 string 值,指定產生金鑰的程式,或包含用來加密和解密資料的文字。 預設為 "AutoGenerate,IsolateApps"。 注意: 使用 「AutoGenerate」 字串來指定 ASP.NET 產生隨機金鑰,並將其儲存在本機安全性授權單位中。 「AutoGenerate」 字串是預設值的一部分。 如果您將 「IsolateApps」 修飾詞新增至 DecryptionKey 值,ASP.NET 使用其應用程式識別碼為每個應用程式產生唯一的加密金鑰。 「IsolateApps」 也是預設值的一部分。 如果您需要支援跨 Web 服務器網路的組態, (Web 服務器陣列) ,請手動設定 DecryptionKey 屬性以確保設定一致。
Location (繼承自 ConfigurationSection .) 索引鍵屬性。
Path (繼承自 ConfigurationSection .) 索引鍵屬性。
SectionInformation (繼承自 ConfigurationSection。)
Validation 讀取/寫入 sint32 值,指定用於驗證資料的加密類型。 可能的值稍後會列在一節中。
ValidationKey 讀取/寫入修剪 string 值,指定產生金鑰的程式,或包含用來驗證加密資料的文字。 預設為 "AutoGenerate,IsolateApps"。 注意:EnableViewStateMACPagesSection類別的 屬性為 true 時,ASP.NET 會使用 ValidationKey 屬性來建立訊息驗證碼,以確保檢視狀態尚未遭到竄改。 驗證金鑰也可用來產生跨進程、應用程式特定的會話識別碼,以確保會話狀態變數在應用程式之間隔離。 使用 「AutoGenerate」 字串來指定 ASP.NET 產生隨機金鑰,並將其儲存在本機安全性授權單位中。 「AutoGenerate」 字串是預設值的一部分。 如果您將 「IsolateApps」 修飾詞新增至 ValidationKey 值,ASP.NET 使用其應用程式識別碼為每個應用程式產生唯一的加密金鑰。 「IsolateApps」 也是預設值的一部分。 如果您需要支援跨 Web 服務器網路的組態, (Web 服務器陣列) ,請手動設定 ValidationKey 屬性以確保設定一致。

子類別

這個類別不包含子類別。

備註

注意

為了讓 MachineKeySection 類別在 Web 服務器網路 (Web 服務器陣列) 運作, MachineKeySection 屬性必須明確且與有效的索引鍵值相同。 「AutoGenerate」 值不適用於 Web 服務器陣列,因為它依賴僅由本機電腦保存的密碼編譯隨機金鑰。 此金鑰無法由任何其他電腦解密。

下表列出 屬性的可能值 Decryption 。 預設值為 「Auto」。

描述
自動 ASP.NET 會決定根據預設組態設定解密資料的演算法。
AES ASP.NET 使用 AES 演算法來解密資料。
3DES ASP.NET 使用 Triple DES 演算法來解密資料。

下表列出 屬性的可能值 Validation 。 預設值為 1 (SHA1) 。

關鍵字 描述
0 MD5 ASP.NET 使用 MD5 (訊息摘要演算法 5) 加密。
1 SHA1 ASP.NET 使用 SHA1 (安全雜湊演算法 1) 加密。
2 3DES ASP.NET 使用三重 DES (資料加密標準) 加密。
3 AES ASP.NET 使用 AES (進階加密標準) 加密。

範例

下列範例會顯示 MachineKeySection 預設網站的設定。

' Connect to the WMI WebAdministration namespace.  
Set oWebAdmin = _  
    GetObject("winmgmts:root\WebAdministration")  
  
' Get the machine key section.  
Set oSite = oWebAdmin.Get("Site.Name='Default Web Site'")  
oSite.GetSection "MachineKeySection", oMKeySection  
  
' Display the path and location.  
WScript.Echo "Machine Key Section Settings"  
WScript.Echo "----------------------------"  
WScript.Echo "Path: " & oMKeySection.Path  
WScript.Echo "Location: " & oMKeySection.Location  
  
' Display the machine key settings.  
WScript.Echo "Decryption: " & oMKeySection.Decryption  
  
WScript.Echo "Decryption Key: " & _  
    oMKeySection.DecryptionKey      
  
WScript.Echo "Validation: " & _  
    ValidationText(oMKeySection.Validation)  
  
WScript.Echo "Validation Key: " & oMKeySection.ValidationKey  
  
' Convert the Validation enumeration values to text.  
Function ValidationText(enumValue)  
    Select Case enumValue  
        Case 0  
            ValidationText = "MD5"  
        Case 1  
            ValidationText = "SHA1"  
        Case 2  
            ValidationText = "3DES"  
        Case 3  
            ValidationText = "AES"  
        Case Else  
            ValidationText = "Undefined enumeration value."  
    End Select  
End Function  
  

繼承階層架構

ConfigurationSection

MachineKeySection

規格需求

類型 描述
Client - Windows Vista 上的 IIS 7.0
- Windows 7 上的 IIS 7.5
- Windows 8 上的 IIS 8.0
- Windows 10上的 IIS 10.0
伺服器 - Windows Server 2008 上的 IIS 7.0
- Windows Server 2008 R2 上的 IIS 7.5
- Windows Server 2012 上的 IIS 8.0
- Windows Server 2012 R2 上的 IIS 8.5
- Windows Server 2016上的 IIS 10.0
產品 - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0
MOF 檔案 WebAdministration.mof

另請參閱

System.Web.Configuration.MachineKeyValidationConfigurationSection 類別
PagesSection 類別