Uredi

HostProtectionAttribute Class

Definition

Caution

Code Access Security is not supported or honored by the runtime.

Allows the use of declarative security actions to determine host protection requirements. This class cannot be inherited.

public ref class HostProtectionAttribute sealed : System::Security::Permissions::CodeAccessSecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Delegate | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
[System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public sealed class HostProtectionAttribute : System.Security.Permissions.CodeAccessSecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Delegate | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
public sealed class HostProtectionAttribute : System.Security.Permissions.CodeAccessSecurityAttribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Delegate | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)>]
[<System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type HostProtectionAttribute = class
    inherit CodeAccessSecurityAttribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Delegate | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)>]
type HostProtectionAttribute = class
    inherit CodeAccessSecurityAttribute
Public NotInheritable Class HostProtectionAttribute
Inherits CodeAccessSecurityAttribute
Inheritance
Attributes

Remarks

Caution

Code Access Security (CAS) has been deprecated across all versions of .NET Framework and .NET. Recent versions of .NET do not honor CAS annotations and produce errors if CAS-related APIs are used. Developers should seek alternative means of accomplishing security tasks.

This attribute affects only unmanaged applications that host the common language runtime and implement host protection, such as SQL Server. If the code is run in a client application or on a server that is not host-protected, the attribute "evaporates"; it is not detected and therefore not applied. When applied, the security action results in the creation of a link demand based on the host resources the class or method exposes.

Important

The purpose of this attribute is to enforce host-specific programming model guidelines, not security behavior. Although a link demand is used to check for conformance to programming model requirements, the HostProtectionAttribute is not a security permission.

If the host does not have programming model requirements, the link demands do not occur.

This attribute identifies the following:

  • Methods or classes that do not fit the host programming model, but are otherwise benign.
  • Methods or classes that do not fit the host programming model and could lead to destabilizing server-managed user code.
  • Methods or classes that do not fit the host programming model and could lead to a destabilization of the server process itself.

Note

If you are creating a class library that is to be called by applications that may execute in a host protected environment, you should apply this attribute to members that expose HostProtectionResource resource categories. The .NET Framework class library members with this attribute cause only the immediate caller to be checked. Your library member must also cause a check of its immediate caller in the same manner.

Note

Do not use the Ngen.exe (Native Image Generator) to create a native image of assemblies that are protected by the HostProtectionAttribute. In a full-trust environment, the image is always loaded, without regard to the HostProtectionAttribute, and in a partial-trust environment the image is not loaded.

Constructors

Name Description
HostProtectionAttribute()

Initializes a new instance of the HostProtectionAttribute class with default values.

HostProtectionAttribute(SecurityAction)

Initializes a new instance of the HostProtectionAttribute class with the specified SecurityAction value.

Properties

Name Description
ExternalProcessMgmt

Gets or sets a value indicating whether external process management is exposed.

ExternalThreading

Gets or sets a value indicating whether external threading is exposed.

MayLeakOnAbort

Gets or sets a value indicating whether resources might leak memory if the operation is terminated.

Resources

Gets or sets flags specifying categories of functionality that are potentially harmful to the host.

SecurityInfrastructure

Gets or sets a value indicating whether the security infrastructure is exposed.

SelfAffectingProcessMgmt

Gets or sets a value indicating whether self-affecting process management is exposed.

SelfAffectingThreading

Gets or sets a value indicating whether self-affecting threading is exposed.

SharedState

Gets or sets a value indicating whether shared state is exposed.

Synchronization

Gets or sets a value indicating whether synchronization is exposed.

UI

Gets or sets a value indicating whether the user interface is exposed.

Methods

Name Description
CreatePermission()

Creates and returns a new host protection permission.

Applies to

See also