<NetFx40_LegacySecurityPolicy > 元素<NetFx40_LegacySecurityPolicy> Element

指定运行时是否使用旧版代码访问安全性 (CAS) 策略。Specifies whether the runtime uses legacy code access security (CAS) policy.

<configuration><configuration>
<运行时 ><runtime>
<NetFx40_LegacySecurityPolicy><NetFx40_LegacySecurityPolicy>

语法Syntax

<NetFx40_LegacySecurityPolicy  
   enabled="true|false"/>  

特性和元素Attributes and Elements

下列各节描述了特性、子元素和父元素。The following sections describe attributes, child elements, and parent elements.

特性Attributes

特性Attribute 描述Description
enabled 必需的特性。Required attribute.

指定运行时是否使用旧版 CAS 策略。Specifies whether the runtime uses legacy CAS policy.

enabled 特性enabled Attribute

“值”Value 描述Description
false 在运行时不使用旧版 CAS 策略。The runtime does not use legacy CAS policy. 这是默认设置。This is the default.
true 运行时使用旧版 CAS 策略。The runtime uses legacy CAS policy.

子元素Child Elements

无。None.

父元素Parent Elements

元素Element 描述Description
configuration 公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中的根元素。The root element in every configuration file used by the common language runtime and .NET Framework applications.
runtime 包含有关运行时初始化选项的信息。Contains information about runtime initialization options.

备注Remarks

在.NET Framework 版本 3.5 和更早版本中,CAS 策略都起作用。In the .NET Framework version 3.5 and earlier versions, CAS policy is always in effect. .NET Framework 4.NET Framework 4,必须启用 CAS 策略。In the .NET Framework 4.NET Framework 4, CAS policy must be enabled.

CAS 策略是特定于版本的。CAS policy is version-specific. .NET Framework 的早期版本中存在的自定义 CA 策略必须中再次指定.NET Framework 4.NET Framework 4Custom CAS policies that exist in earlier versions of the .NET Framework must be respecified in the .NET Framework 4.NET Framework 4.

将应用<NetFx40_LegacySecurityPolicy>元素.NET Framework 4.NET Framework 4程序集不会影响安全透明代码; 透明度规则仍然适用。Applying the <NetFx40_LegacySecurityPolicy> element to a .NET Framework 4.NET Framework 4 assembly does not affect security-transparent code; the transparency rules still apply.

重要

将应用<NetFx40_LegacySecurityPolicy>元素创建的本机映像程序集可能导致显著的性能损失本机映像生成器 (Ngen.exe)是否未安装在全局程序集缓存.Applying the <NetFx40_LegacySecurityPolicy> element can result in significant performance penalties for native image assemblies created by the Native Image Generator (Ngen.exe) that are not installed in the global assembly cache. 性能下降由运行时无法应用该特性为本机图像加载程序集,从而导致其被加载,在实时程序集。The performance degradation is caused by the inability of the runtime to load the assemblies as native images when the attribute is applied, resulting in their being loaded as just-in-time assemblies.

备注

如果指定的目标.NET Framework 版本早于.NET Framework 4.NET Framework 4在项目设置为你的 Visual Studio 项目中,CAS 策略将启用,包括为该版本指定任何自定义 CA 策略。If you specify a target .NET Framework version that is earlier than the .NET Framework 4.NET Framework 4 in the project settings for your Visual Studio project, CAS policy will be enabled, including any custom CAS policies you specified for that version. 但是,你将无法再使用新的.NET Framework 4.NET Framework 4类型和成员。However, you will not be able to use new .NET Framework 4.NET Framework 4 types and members. 此外可以通过使用指定的.NET framework 早期版本 <supportedRuntime > 元素启动设置架构中你应用程序配置文件You can also specify an earlier version of the .NET Framework by using the <supportedRuntime> element in the startup settings schema in your application configuration file.

备注

配置文件语法是区分大小写。Configuration file syntax is case-sensitive. 在语法和示例部分中所述,应使用语法。You should use the syntax as provided in the Syntax and Example sections.

配置文件Configuration File

仅在应用程序配置文件中,可以使用此元素。This element can be used only in the application configuration file.

示例Example

下面的示例演示如何启用旧版 CAS 策略的应用程序。The following example shows how to enable legacy CAS policy for an application.

<configuration>  
   <runtime>  
      <NetFx40_LegacySecurityPolicy enabled="true"/>  
   </runtime>  
</configuration>  

请参阅See also