Type.IsSecurityCritical Property


取得值,這個值表示目前類型在目前信任層級上是否為安全性關鍵或安全性安全關鍵,因而可以執行重要的作業。Gets a value that indicates whether the current type is security-critical or security-safe-critical at the current trust level, and therefore can perform critical operations.

 virtual property bool IsSecurityCritical { bool get(); };
public virtual bool IsSecurityCritical { get; }
member this.IsSecurityCritical : bool
Public Overridable ReadOnly Property IsSecurityCritical As Boolean

Property Value


如果目前類型在目前信任層級上為安全性關鍵或安全性安全關鍵,則為 true,如果是安全性透明,則為 falsetrue if the current type is security-critical or security-safe-critical at the current trust level; false if it is transparent.


IsSecurityCriticalIsSecuritySafeCriticalIsSecurityTransparent 屬性會在其目前的信任層級上,報告類型的透明度層級,如同 common language runtime (CLR)所決定。The IsSecurityCritical, IsSecuritySafeCritical, and IsSecurityTransparent properties report the transparency level of the type at its current trust level, as determined by the common language runtime (CLR). 下表顯示這些屬性的組合:The combinations of these properties are shown in the following table:

安全性層級Security level IsSecurityCriticalIsSecurityCritical IsSecuritySafeCriticalIsSecuritySafeCritical IsSecurityTransparentIsSecurityTransparent
重大Critical true false false
安全關鍵Safe critical true true false
透明Transparent false false true

使用這些屬性會比檢查組件及其類型的安全性註釋、檢查目前的信任層級,以及嘗試複製執行階段規則更簡單。Using these properties is much simpler than examining the security annotations of an assembly and its types, checking the current trust level, and attempting to duplicate the runtime's rules.


對於部分信任元件,這個屬性的值會根據元件的目前信任層級而定。For partial-trust assemblies, the value of this property depends on the current trust level of the assembly. 如果將元件載入至部分信任的應用程式域(例如,進入沙箱應用程式域中),則執行時間會忽略元件的安全性批註。If the assembly is loaded into a partially trusted application domain (for example, into a sandboxed application domain), then the runtime ignores the security annotations of the assembly. 元件和其所有類型都會被視為透明。The assembly and all its types are treated as transparent. 只有在將元件載入到完全信任的應用程式域(例如,到桌面應用程式的預設應用程式域中)時,執行時間才會特別注意部分信任元件的安全性批註。The runtime pays attention to the security annotations of a partial-trust assembly only when that assembly is loaded into a fully trusted application domain (for example, into the default application domain of a desktop application). 相反地,不論應用程式域的信任層級為何,受信任的元件(也就是安裝在全域組件快取中的強式名稱元件)一律會以完全信任的方式載入,因此目前的信任層級一律完全受信任。By contrast, a trusted assembly (that is, a strong-named assembly that is installed in the global assembly cache) is always loaded with full trust regardless of the trust level of the application domain, so its current trust level is always fully trusted. 您可以使用 Assembly.IsFullyTrustedAppDomain.IsFullyTrusted 屬性,判斷元件和應用程式域的目前信任層級。You can determine the current trust levels of assemblies and application domains by using the Assembly.IsFullyTrusted and AppDomain.IsFullyTrusted properties.

如需反映和透明度的詳細資訊,請參閱反映的安全性考慮For more information about reflection and transparency, see Security Considerations for Reflection. 如需透明度的詳細資訊,請參閱安全性變更For information about transparency, see Security Changes.

Applies to

See also