securityPolicy 的 trustLevel 元素(ASP.NET 设置架构)

向安全策略映射集合添加安全策略文件与指定的安全信任级别之间的映射。 然后,可以通过在 trust 元素的 level 特性中指定信任级别名称,将安全策略文件应用于 ASP.NET 应用程序。

<trustLevel 
   name="trust level name" 
   policyFile="file name" 
/>

特性和元素

以下几节描述了属性、子元素和父元素。

特性

特性

说明

name

必选的 String 特性。

指定映射到策略文件的命名的安全级别。

该特性可以是用户定义的值或下面某个可能的值

值说明
Full 指定 ASP.NET 不通过应用程序域特定的策略来限制安全策略。没有与 Full 关联的安全策略文件。默认情况下,此信任级别名称映射到 policyFile 特性中的 "internal"。
High 为策略文件映射指定高级别安全性。默认情况下,此信任级别名称映射到 Web_hightrust.config 策略文件。
Medium 为策略文件映射指定中级别安全性。默认情况下,此信任级别名称映射到 Web_mediumtrust.config 策略文件。
Low 为策略文件映射指定低级别安全性。默认情况下,此信任级别名称映射到 Web_lowtrust.config 策略文件。
Minimal 为策略文件映射指定最低级别安全性。默认情况下,此信任级别名称映射到 Web_minimaltrust.config 策略文件。
User Defined 指定用户定义的信任级别的名称。有关更多信息,请参见 管理安全策略

有关每个信任级别允许操作的说明,请参见 AspNetHostingPermissionLevel信任

policyFile

必选 String 特性。

为已命名安全级别指定包含安全策略设置的配置文件。 配置文件必须与包含 trustLevel 定义的配置文件位于相同的目录中。

子元素

无。

父元素

元素

说明

configuration

指定公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中均需要的根元素。

system.web

指定配置文件中 ASP.NET 配置设置的根元素,并且包含各种配置元素,这些配置元素配置 ASP.NET Web 应用程序并控制这些应用程序的行为方式。

securityPolicy

定义安全策略文件与关联的信任级别名称之间的映射的集合。

备注

通过提供映射到 policyFile 特性指定的文件、由您自己命名的 <trustLevel> 元素,可以扩展安全系统。 有关 ASP.NET 和策略文件的信息,请参见 ASP.NET 信任级别和策略文件管理安全策略

由于 ASP.NET 对 Full 信任特别对待,因此 Full 信任没有关联的策略文件。 如果设置为 Full,则 ASP.NET 主机不会向应用程序添加额外的应用程序域级别策略。 Full 信任级别始终映射到内部处理程序,并且 policyFile 特性被忽略。

默认配置

下面的默认 trustLevel 元素在根 Web.config 文件中配置。

<location allowOverride="true">
<system.web>
   <securityPolicy>
      <trustLevel name="Full" policyFile="internal" />
      <trustLevel name="High" policyFile="web_hightrust.config" />
      <trustLevel name="Medium" policyFile="web_mediumtrust.config" />
      <trustLevel name="Low" policyFile="web_lowtrust.config" />
      <trustLevel name="Minimal" policyFile="web_minimaltrust.config"/>
   </securityPolicy>
   <trust 
      level="Full" 
      originUrl="" 
      processRequestInApplicationTrust="true" 
   />
</system.web>
</location>

示例

下面的代码示例演示如何为 ASP.NET 应用程序指定一个自定义信任级别名称和策略文件并向继承的集合添加安全策略映射。

<securityPolicy>
   <trustLevel 
      name="CustomTrustLevel" 
      policyFile="customtrust.config"
   />
</securityPolicy>

元素信息

配置节处理程序

System.Web.Configuration.SecurityPolicySection

配置成员

SecurityPolicySection.TrustLevels

TrustLevelCollection.Add

System.Web.Configuration.TrustLevel

可配置的位置

Machine.config

根级别的 Web.config

应用程序级别的 Web.config

要求

Microsoft Internet 信息服务 (IIS) 版本 5.0、5.1 或 6.0

.NET Framework 版本 1.0、1.1 或 2.0

Microsoft Visual Studio 2003 或 Visual Studio 2005

请参见

任务

如何:使用位置设置配置特定目录

如何:锁定 ASP.NET 配置设置

参考

securityPolicy 元素(ASP.NET 设置架构)

system.web 元素(ASP.NET 设置架构)

configuration 元素(常规设置架构)

trust 元素(ASP.NET 设置架构)

System.Configuration

System.Web.Configuration

System.Web.Configuration.SecurityPolicySection

System.Web.Configuration.TrustLevel

概念

ASP.NET 信任级别和策略文件

管理安全策略

保证 ASP.NET 配置的安全

ASP.NET 配置方案

其他资源

ASP.NET Web 应用程序安全性

常规配置设置 (ASP.NET)

ASP.NET 配置设置

ASP.NET 网站管理

ASP.NET 配置文件

ASP.NET 配置 API