<NetFx40_LegacySecurityPolicy > 元素<NetFx40_LegacySecurityPolicy> Element

指定執行階段是否使用舊版程式碼存取安全性 (CAS) 原則。Specifies whether the runtime uses legacy code access security (CAS) policy.

<configuration> <configuration>
    <runtime >   <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 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 中,必須啟用 CAS 原則。In the .NET Framework 4, CAS policy must be enabled.

CAS 原則是特定版本。CAS policy is version-specific. 存在於舊版 .NET Framework 中的自訂 CAS 原則必須在 .NET Framework 4 中 respecified。Custom CAS policies that exist in earlier versions of the .NET Framework must be respecified in the .NET Framework 4.

<NetFx40_LegacySecurityPolicy> 專案套用至 .NET Framework 4 元件,並不會影響到安全性透明的程式碼;透明度規則仍然適用。Applying the <NetFx40_LegacySecurityPolicy> element to a .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.

注意

如果您在 Visual Studio 專案的專案設定中指定早于 .NET Framework 4 的目標 .NET Framework 版本,將會啟用 CAS 原則,包括您為該版本指定的任何自訂 CAS 原則。If you specify a target .NET Framework version that is earlier than the .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 種類型和成員。However, you will not be able to use new .NET Framework 4 types and members. 您也可以在應用程式佈建檔的 [啟動設定] 架構中,使用<supportedruntime> > 元素,指定舊版的 .NET Framework。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