為 Web 服務器上的 Web 應用程式設定信任層級。
Syntax
class TrustLevel : CollectionElement
方法
這個類別不包含任何方法。
屬性
下表列出 類別所 TrustLevel 公開的屬性。
| 名稱 | 描述 |
|---|---|
Name |
必要的唯讀 string 值,指定對應至原則檔的具名安全性層級。 後續的一節會列出可能的值。 索引鍵屬性。 |
PolicyFile |
必要的讀取/寫入 string 值,指定組態檔,其中包含 屬性中所 Name 指定安全性層級的安全性原則設定。 預設值為 「internal」。原則檔案必須位於與電腦層級Web.config檔案相同的目錄中。 此目錄預設為 %windir%\Microsoft.NET\Framework\{version}\Config。 您可以在TrustSection類別的 屬性中 Level 指定信任層級名稱,將安全性原則檔案套用至 ASP.NET 應用程式。 |
子類別
這個類別不包含子類別。
備註
這個類別的實例包含在 SecurityPolicySecurityPolicySection 類別的 屬性中。
您可以藉由設定信任層級,為伺服器上的所有 Web 應用程式建立安全性原則。 由於信任層級只能在電腦層級定義,因此組態檔必須在電腦層級組態目錄中設定層級。 根據預設,此目錄為 %windir%\Microsoft.NET\Framework\{version}\Config。
您可以將電腦層級Web.config檔案中的具名 <trustLevel> 元素對應至自訂原則組態檔,以建立自訂原則。 自訂原則組態檔也必須位於電腦層級的組態目錄中。
下表列出 屬性的 Name 可能值。 預設值為「Full」。 如需每個信任層級允許之內容的說明,請參閱 TrustSection 類別。
| 值 | 說明 |
|---|---|
"Full" |
指定 ASP.NET 不會使用應用程式域特定原則來限制安全性原則。 沒有與 相關聯的 Full 安全性原則檔案。 根據預設,這個信任層級值會對應至 屬性中的 PolicyFile 「內部」。
注意: 因為 ASP.NET 將完全信任視為特殊案例,所以完全信任沒有相關聯的原則檔案。 如果已設定 Full,則 ASP.NET 主機不會將額外的網域層級原則新增至應用程式。 完全信任層級一律會對應至內部處理常式,並 PolicyFile 忽略 屬性。 |
"High" |
指定原則檔案對應的高階安全性。 根據預設,此信任層級值會對應至Web_hightrust.config原則檔。 |
"Medium" |
指定原則檔案對應的中層級安全性。 根據預設,此信任層級值會對應至Web_mediumtrust.config原則檔。 |
"Low" |
指定原則檔案對應的低層級安全性。 根據預設,此信任層級值會對應至Web_lowtrust.config原則檔。 |
"Minimal" |
指定原則檔案對應的最低安全性層級。 根據預設,此信任層級值會對應至Web_minimaltrust.config原則檔。 |
"User Defined" |
指定使用者定義信任層級的名稱。 如需詳細資訊,請參閱 管理安全性原則。 |
範例
下列範例會顯示電腦層級Web.config檔案中指定的信任層級名稱和對應的安全性原則組態檔。
' Connect to the WMI WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
' Get the security policy section.
Set oSite = oWebAdmin.Get("Site.Name='Default Web Site'")
oSite.GetSection "SecurityPolicySection", oSection
' Display the path and location.
WScript.Echo "Path: " & oSection.Path
WScript.Echo "Location: " & oSection.Location
WScript.Echo
' Display the security level names and their policy files.
For Each oTrustLevel In oSection.SecurityPolicy
WScript.Echo "Security level: " & oTrustLevel.Name
WScript.Echo " Policy file: " & oTrustLevel.PolicyFile
WScript.Echo
Next
繼承階層架構
TrustLevel
規格需求
| 類型 | Description |
|---|---|
| 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.TrustLevel管理安全性原則
ASP.NET Trust Levels and Policy Files
CollectionElement 類別
SecurityPolicySection 類別
securityPolicy 的 trustLevel 項目 (ASP.NET 設定結構描述)