HostProtectionAttribute クラス

定義

注意事項

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

ホスト保護要件を決める宣言セキュリティ アクションの使用を許可します。 このクラスは継承できません。

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)]
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}")]
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.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
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)>]
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)>]
[<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)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type HostProtectionAttribute = class
    inherit CodeAccessSecurityAttribute
Public NotInheritable Class HostProtectionAttribute
Inherits CodeAccessSecurityAttribute
継承
属性

次のコード例は、 属性をさまざまなHostProtectionResource値と共に使用HostProtectionAttributeする方法を示しています。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::IO;
using namespace System::Threading;
using namespace System::Security;
using namespace System::Security::Policy;
using namespace System::Security::Principal;
using namespace System::Security::Permissions;
using namespace System::Diagnostics;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using namespace System::Security::Permissions;

// The following class is an example of code that exposes external process management.
// Add the LicenseProviderAttribute to the control.

[LicenseProvider(LicFileLicenseProvider::typeid)]
public ref class MyControl: public System::Windows::Forms::Control
{
private:

   // Create a new, null license.
   License^ license;

public:
   [HostProtection(ExternalProcessMgmt=true)]
   MyControl()
   {
      license = nullptr;
      
      // Determine if a valid license can be granted.
      bool isValid = LicenseManager::IsValid( MyControl::typeid );
      Console::WriteLine( "The result of the IsValid method call is {0}", isValid );
   }

};

// If this application is run on a server that implements host protection, the HostProtection attribute  
// is applied. If the application is run on a server that is not host-protected, the attribute 
// evaporates; it is not detected and therefore not applied. HostProtection can be configured with 
// members of the HostProtectionResource enumeration to customize the protection offered. 
// The primary intent of this sample is to show situations in which the HostProtection attribute
// might be meaningfully used.  The environment required to demonstrate a particular HostProtection is
// too complex to invoke within the scope of this sample.
public ref class HostProtectionExample
{
public:
   static int Success = 100;

private:

   // Use the enumeration flags to indicate that this method exposes shared state and 
   // self-affecting process management.
   // Either of the following attribute statements can be used to set the 
   // resource flags.
   // Exit the sample when an exception is thrown.

   [HostProtection(SharedState=true,SelfAffectingProcessMgmt=true)]
   [HostProtection(Resources=HostProtectionResource::SharedState|
   HostProtectionResource::SelfAffectingProcessMgmt)]
   static void Exit( String^ Message, int Code )
   {
      Console::WriteLine( "\nFAILED: {0} {1}", Message, Code );
      Environment::ExitCode = Code;
      Environment::Exit( Code );
   }

   // Use the enumeration flags to indicate that this method exposes shared state, 
   // self-affecting process management, and self-affecting threading.
   // This method allows the user to quit the sample.

   [HostProtection(SharedState=true,SelfAffectingProcessMgmt=true,
   SelfAffectingThreading=true,UI=true)]
   static void ExecuteBreak()
   {
      Console::WriteLine( "Executing Debugger.Break." );
      Debugger::Break();
      Debugger::Log( 1, "info", "test message" );
   }

   // Use the enumeration flags to indicate that this method exposes shared state, 
   // self-affecting threading and the security infrastructure.
   // ApplyIdentity sets the current identity.

   [HostProtection(SharedState=true,SelfAffectingThreading=true,
   SecurityInfrastructure=true)]
   static int ApplyIdentity()
   {
      array<String^>^roles = {"User"};
      try
      {
         AppDomain^ mAD = AppDomain::CurrentDomain;
         GenericPrincipal^ mGenPr = gcnew GenericPrincipal( WindowsIdentity::GetCurrent(),roles );
         mAD->SetPrincipalPolicy( PrincipalPolicy::WindowsPrincipal );
         mAD->SetThreadPrincipal( mGenPr );
         return Success;
      }
      catch ( Exception^ e ) 
      {
         Exit( e->ToString(), 5 );
      }

      return 0;
   }

public:

   // The following method is started on a separate thread.
   [PermissionSet(SecurityAction::Demand, Name="FullTrust")]
   static void WatchFileEvents()
   {
      try
      {
         Console::WriteLine( "In the child thread." );
         FileSystemWatcher^ watcher = gcnew FileSystemWatcher;
         watcher->Path = "C:\\Temp";
         
         // Watch for changes in LastAccess and LastWrite times, and 
         // name changes to files or directories. 
         watcher->NotifyFilter = static_cast<NotifyFilters>(NotifyFilters::LastAccess | NotifyFilters::LastWrite | NotifyFilters::FileName | NotifyFilters::DirectoryName);
         
         // Watch only text files.
         watcher->Filter = "*.txt";
         
         // Add event handlers.
         watcher->Changed += gcnew FileSystemEventHandler( OnChanged );
         watcher->Created += gcnew FileSystemEventHandler( OnChanged );
         watcher->Deleted += gcnew FileSystemEventHandler( OnChanged );
         
         // Begin watching.
         watcher->EnableRaisingEvents = true;
         
         // Wait for the user to quit the program.
         Console::WriteLine( "Event handlers have been enabled." );
         while ( Console::Read() != 'q' )
                  ;
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( e->Message );
      }

   }


private:

   // Use the enumeration flags to indicate that this method exposes synchronization 
   //  and external threading.

   [HostProtection(Synchronization=true,ExternalThreading=true)]
   static void StartThread()
   {
      Thread^ t = gcnew Thread( gcnew ThreadStart( WatchFileEvents ) );
      
      // Start the new thread.  On a uniprocessor, the thread is not given 
      // any processor time until the main thread yields the processor.  
      t->Start();
      
      // Give the new thread a chance to execute.
      Thread::Sleep( 1000 );
   }

public:

   // Call methods that show the use of the HostProtectionResource enumeration.
   [HostProtection(Resources=HostProtectionResource::All)]
   static int Main()
   {
      try
      {
         
         // Show use of the HostProtectionResource.SharedState,
         //   HostProtectionResource.SelfAffectingThreading, and
         //   HostProtectionResource.Security enumeration values.
         ApplyIdentity();
         Directory::CreateDirectory( "C:\\Temp" );
         
         // Show use of the HostProtectionResource.Synchronization and
         //   HostProtectionResource.ExternalThreading enumeration values.
         StartThread();
         Console::WriteLine( "In the main thread." );
         Console::WriteLine( "Deleting and creating 'MyTestFile.txt'." );
         if ( File::Exists( "C:\\Temp\\MyTestFile.txt" ) )
         {
            File::Delete( "C:\\Temp\\MyTestFile.txt" );
         }
         StreamWriter^ sr = File::CreateText( "C:\\Temp\\MyTestFile.txt" );
         sr->WriteLine( "This is my file." );
         sr->Close();
         Thread::Sleep( 1000 );
         
         // Show use of the HostProtectionResource.SharedState,
         //   HostProtectionResource.SelfProcessMgmt,
         //   HostProtectionResource.SelfAffectingThreading, and
         //   HostProtectionResource.UI enumeration values.
         ExecuteBreak();
         
         // Show the use of the HostProtectionResource.ExternalProcessManagement enumeration value.
         MyControl^ myControl = gcnew MyControl;
         Console::WriteLine( "Enter 'q' to quit the sample." );
         return 100;
      }
      catch ( Exception^ e ) 
      {
         Exit( e->ToString(), 0 );
         return 0;
      }
   }

   // Define the event handlers.
   private:
   static void OnChanged( Object^ /*source*/, FileSystemEventArgs^ e )
   {
      
      // Specify whether a file is changed, created, or deleted.
      Console::WriteLine( "In the OnChanged event handler." );
      Console::WriteLine( "File: {0} {1}", e->FullPath, e->ChangeType );
   }

};

int main()
{
   return HostProtectionExample::Main();
}
using System;
using System.IO;
using System.Threading;
using System.Security;
using System.Security.Policy;
using System.Security.Principal;
using System.Security.Permissions;
using System.Diagnostics;
using System.ComponentModel;
using System.Windows.Forms;

// If this application is run on a server that implements host protection, the 
// HostProtectionAttribute attribute is applied. If the application is run on   
// a server that is not host-protected, the attribute evaporates; it is not  
// detected and therefore not applied. Host protection can be configured with  
// members of the HostProtectionResource enumeration to customize the  
// protection offered.
// The primary intent of this sample is to show situations in which the 
// HostProtectionAttribute attribute might be meaningfully used. The  
// environment required to demonstrate a particular behavior is
// too complex to invoke within the scope of this sample.

class HostProtectionExample
{
    public static int Success = 100;
    
    // Use the enumeration flags to indicate that this method exposes 
    // shared state and self-affecting process management.
    // Either of the following attribute statements can be used to set the
    // resource flags.
    [HostProtectionAttribute(SharedState = true, 
        SelfAffectingProcessMgmt = true)]
    [HostProtectionAttribute(Resources = HostProtectionResource.SharedState |
         HostProtectionResource.SelfAffectingProcessMgmt)]
    private static void Exit(string Message, int Code)
    {
        // Exit the sample when an exception is thrown.
        Console.WriteLine("\nFAILED: " + Message + " " + Code.ToString());
        Environment.ExitCode = Code;
        Environment.Exit(Code);
    }

    // Use the enumeration flags to indicate that this method exposes shared 
    // state, self-affecting process management, and self-affecting threading.
    [HostProtectionAttribute(SharedState=true, SelfAffectingProcessMgmt=true,
         SelfAffectingThreading=true, UI=true)]
    // This method allows the user to quit the sample.
    private static void ExecuteBreak()
    {
        Console.WriteLine("Executing Debugger.Break.");
        Debugger.Break();
        Debugger.Log(1,"info","test message");
    }
    
    // Use the enumeration flags to indicate that this method exposes shared 
    // state, self-affecting threading, and the security infrastructure.
    [HostProtectionAttribute(SharedState=true, SelfAffectingThreading=true,
         SecurityInfrastructure=true)]
    // ApplyIdentity sets the current identity.
    private static int ApplyIdentity()
    {
        string[] roles = {"User"};
        try
        {
            AppDomain mAD = AppDomain.CurrentDomain;
            GenericPrincipal mGenPr = 
                new GenericPrincipal(WindowsIdentity.GetCurrent(), roles);
            mAD.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
            mAD.SetThreadPrincipal(mGenPr);
            return Success;
        }
        catch (Exception e)
        {
            Exit(e.ToString(), 5);
        }
        return 0;
    }

    // The following method is started on a separate thread.
    public static void WatchFileEvents()
    {
        try
        {
            Console.WriteLine("In the child thread.");
            FileSystemWatcher watcher = new FileSystemWatcher();
            watcher.Path = "C:\\Temp";
            
            // Watch for changes in LastAccess and LastWrite times, and
            // name changes to files or directories.
            watcher.NotifyFilter = NotifyFilters.LastAccess 
                | NotifyFilters.LastWrite
                | NotifyFilters.FileName | NotifyFilters.DirectoryName;
            
            // Watch only text files.
            watcher.Filter = "*.txt";

            // Add event handlers.
            watcher.Changed += new FileSystemEventHandler(OnChanged);
            watcher.Created += new FileSystemEventHandler(OnChanged);
            watcher.Deleted += new FileSystemEventHandler(OnChanged);
            
            // Begin watching.
            watcher.EnableRaisingEvents = true;

            // Wait for the user to quit the program.
            Console.WriteLine("Event handlers have been enabled.");
            while(Console.Read()!='q');
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
    }

    // Use the enumeration flags to indicate that this method exposes 
    // synchronization and external threading.
    [HostProtectionAttribute(Synchronization=true, ExternalThreading=true)]
    private static void StartThread()
    {
        Thread t = new Thread(new ThreadStart(WatchFileEvents));
        
        // Start the new thread. On a uniprocessor, the thread is not given
        // any processor time until the main thread yields the processor.
        t.Start();
        
        // Give the new thread a chance to execute.
        Thread.Sleep(1000);
    }

    // Call methods that show the use of the HostProtectionResource enumeration.
    [HostProtectionAttribute(Resources=HostProtectionResource.All)]
    static int Main(string [] args)
    {
        try
        {
            // Show use of the HostProtectionResource.SharedState,
            // HostProtectionResource.SelfAffectingThreading, and
            // HostProtectionResource.Security enumeration values.
            ApplyIdentity();
            Directory.CreateDirectory("C:\\Temp");
            
            // Show use of the HostProtectionResource.Synchronization and
            // HostProtectionResource.ExternalThreading enumeration values.
            StartThread();
            Console.WriteLine("In the main thread.");
            Console.WriteLine("Deleting and creating 'MyTestFile.txt'.");
            if (File.Exists("C:\\Temp\\MyTestFile.txt"))
            {
                File.Delete("C:\\Temp\\MyTestFile.txt");
            }

            StreamWriter sr = File.CreateText("C:\\Temp\\MyTestFile.txt");
            sr.WriteLine ("This is my file.");
            sr.Close();
            Thread.Sleep(1000);
            
            // Show use of the HostProtectionResource.SharedState,
            // HostProtectionResource.SelfProcessMgmt,
            // HostProtectionResource.SelfAffectingThreading, and
            // HostProtectionResource.UI enumeration values.
            ExecuteBreak();
            
            // Show the use of the 
            // HostProtectionResource.ExternalProcessManagement 
            // enumeration value.
            MyControl myControl = new MyControl ();
            Console.WriteLine ("Enter 'q' to quit the sample.");
            return 100;
        }
        catch (Exception e)
        {
            Exit(e.ToString(), 0);
            return 0;
        }
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e)
    {
        // Specify whether a file is changed, created, or deleted.
        Console.WriteLine("In the OnChanged event handler.");
        Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
    }
}

// The following class is an example of code that exposes 
// external process management.
// Add the LicenseProviderAttribute to the control.
[LicenseProvider (typeof(LicFileLicenseProvider))]
public class MyControl : System.Windows.Forms.Control
{
    // Create a new, null license.
    private License license = null;

    [HostProtection (ExternalProcessMgmt = true)]
    public MyControl ()
    {
        // Determine if a valid license can be granted.
        bool isValid = LicenseManager.IsValid (typeof(MyControl));
        Console.WriteLine ("The result of the IsValid method call is " + 
            isValid.ToString ());
    }

    protected override void Dispose (bool disposing)
    {
        if (disposing)
        {
            if (license != null)
            {
                license.Dispose ();
                license = null;
            }
        }
    }
}
Imports System.IO
Imports System.Threading
Imports System.Security
Imports System.Security.Policy
Imports System.Security.Principal
Imports System.Security.Permissions
Imports System.Diagnostics
Imports System.ComponentModel
Imports System.Windows.Forms


' If this application is run on a server that implements host protection, the
' HostProtectionAttribute attribute is applied. If the application is run on 
' a server that is not host-protected, the attribute evaporates; it is not  
' detected and therefore not applied. Host protection can be configured with  
' members of the HostProtectionResource enumeration to customize the  
' protection offered. 
' The primary intent of this sample is to show situations in which the 
' HostProtectionAttribute attribute might be meaningfully used.  The 
' environment required to demonstrate a particular behavior is too 
' complex to invoke within the scope of this sample.

Class HostProtectionExample
    Public Shared Success As Integer = 100

    ' Use the enumeration flags to indicate that this method exposes 
    ' shared state and self-affecting process management.
    ' Either of the following attribute statements can be used to set the 
    ' resource flags.
    <HostProtectionAttribute(SharedState := True, _
        SelfAffectingProcessMgmt := True), _
        HostProtectionAttribute( _
        Resources := HostProtectionResource.SharedState Or _
        HostProtectionResource.SelfAffectingProcessMgmt)> _
    Private Shared Sub [Exit](ByVal Message As String, ByVal Code As Integer)

        ' Exit the sample when an exception is thrown.
        Console.WriteLine((ControlChars.Lf & "FAILED: " & Message & " " & _
            Code.ToString()))
        Environment.ExitCode = Code
        Environment.Exit(Code)
    End Sub

    ' Use the enumeration flags to indicate that this method exposes shared
    ' state, self-affecting process management, and self-affecting threading.
    <HostProtectionAttribute(SharedState := True, _
        SelfAffectingProcessMgmt := True, _
        SelfAffectingThreading := True, UI := True)> _
    Private Shared Sub ExecuteBreak()

        ' This method allows the user to quit the sample.
        Console.WriteLine("Executing Debugger.Break.")
        Debugger.Break()
        Debugger.Log(1, "info", "test message")
    End Sub

    ' Use the enumeration flags to indicate that this method exposes shared  
    ' state, self-affecting threading, and the security infrastructure.
    <HostProtectionAttribute(SharedState := True, _
        SelfAffectingThreading := True, _
        SecurityInfrastructure := True)> _
    Private Shared Function ApplyIdentity() As Integer

        ' ApplyIdentity sets the current identity.
        Dim roles(1) As String
        Try
            Dim mAD As AppDomain = AppDomain.CurrentDomain
            Dim mGenPr As _
                New GenericPrincipal(WindowsIdentity.GetCurrent(), roles)
            mAD.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
            mAD.SetThreadPrincipal(mGenPr)
            Return Success
        Catch e As Exception
            [Exit](e.ToString(), 5)
        End Try
        Return 0
    End Function 'ApplyIdentity

    ' The following method is started on a separate thread.
    Public Shared Sub WatchFileEvents()
        Try
            Console.WriteLine("In the child thread.")
            Dim watcher As New FileSystemWatcher()
            watcher.Path = "C:\Temp"

            ' Watch for changes in LastAccess and LastWrite times, and 
            ' name changes to files or directories. 
            watcher.NotifyFilter = NotifyFilters.LastAccess Or _
                NotifyFilters.LastWrite Or NotifyFilters.FileName Or _
                NotifyFilters.DirectoryName

            ' Watch only text files.
            watcher.Filter = "*.txt"

            ' Add event handlers.
            AddHandler watcher.Changed, AddressOf OnChanged
            AddHandler watcher.Created, AddressOf OnChanged
            AddHandler watcher.Deleted, AddressOf OnChanged

            ' Begin watching.
            watcher.EnableRaisingEvents = True

            ' Wait for the user to quit the program.
            Console.WriteLine("Event handlers have been enabled.")
            While Console.ReadLine() <> "q"c
            End While
        Catch e As Exception
            Console.WriteLine(e.Message)
        End Try
    End Sub

    ' Use the enumeration flags to indicate that this method exposes  
    ' synchronization and external threading.
    <HostProtectionAttribute(Synchronization := True, _
        ExternalThreading := True)> _
    Private Shared Sub StartThread()
        Dim t As New Thread(New ThreadStart(AddressOf WatchFileEvents))

        ' Start the new thread. On a uniprocessor, the thread is not given 
        ' any processor time until the main thread yields the processor.  
        t.Start()

        ' Give the new thread a chance to execute.
        Thread.Sleep(1000)
    End Sub

    ' Call methods that show the use of the HostProtectionResource enumeration.
    <HostProtectionAttribute(Resources := HostProtectionResource.All)> _
    Overloads Shared Function Main(ByVal args() As String) As Integer
        Try
            ' Show use of the HostProtectionResource.SharedState,
            ' HostProtectionResource.SelfAffectingThreading, and
            ' HostProtectionResource.Security enumeration values.
            ApplyIdentity()
            Directory.CreateDirectory("C:\Temp")

            ' Show use of the HostProtectionResource.Synchronization and
            ' HostProtectionResource.ExternalThreading enumeration values.
            StartThread()
            Console.WriteLine("In the main thread.")
            Console.WriteLine("Deleting and creating 'MyTestFile.txt'.")
            If File.Exists("C:\Temp\MyTestFile.txt") Then
                File.Delete("C:\Temp\MyTestFile.txt")
            End If

            Dim sr As StreamWriter = File.CreateText("C:\Temp\MyTestFile.txt")
            sr.WriteLine("This is my file.")
            sr.Close()
            Thread.Sleep(1000)

            ' Show use of the HostProtectionResource.SharedState, 
            ' HostProtectionResource.SelfProcessMgmt,
            ' HostProtectionResource.SelfAffectingThreading, and
            ' HostProtectionResource.UI enumeration values.
            ExecuteBreak()

            ' Show the use of the 
            ' HostProtectionResource.ExternalProcessManagement 
            ' enumeration value.
            Dim myControl As New MyControl()
            Console.WriteLine("Enter 'q' to quit the sample.")
            Return 100
        Catch e As Exception
            [Exit](e.ToString(), 0)
            Return 0
        End Try
    End Function 'Main

    ' Define the event handlers.
    Private Shared Sub OnChanged(ByVal [source] As Object, _
        ByVal e As FileSystemEventArgs)

        ' Specify whether a file is changed, created, or deleted.
        Console.WriteLine("In the OnChanged event handler.")
        Console.WriteLine(("File: " & e.FullPath & " " & _
            e.ChangeType.ToString()))
    End Sub
End Class

' The following class is an example of code that exposes 
' external process management.
' Add the LicenseProviderAttribute to the control.
<LicenseProvider(GetType(LicFileLicenseProvider))> _
Public Class MyControl
    Inherits System.Windows.Forms.Control

    ' Create a new, null license.
    Private license As License = Nothing

    <HostProtectionAttribute(ExternalProcessMgmt := True)> _
    Public Sub New()

        ' Determine if a valid license can be granted.
        Dim isValid As Boolean = LicenseManager.IsValid(GetType(MyControl))
        Console.WriteLine(("The result of the IsValid method call is " & _
            isValid.ToString()))
    End Sub

    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (license Is Nothing) Then
                license.Dispose()
                license = Nothing
            End If
        End If
    End Sub
End Class

注釈

注意事項

コード アクセス セキュリティ (CAS) は、.NET Framework と .NET のすべてのバージョンで非推奨になりました。 最近のバージョンの .NET では、CAS 関連の API が使われている場合、CAS の注釈は使われず、エラーが発生します。 開発者は、代わりの手段を見つけてセキュリティ タスクを実現する必要があります。

この属性は、共通言語ランタイムをホストし、SQL Serverなどのホスト保護を実装するアンマネージ アプリケーションにのみ影響します。 コードがホスト保護されていないクライアント アプリケーションまたはサーバーで実行される場合、この属性は "消滅" します。つまり、検出されないため適用されません。 HPA を適用すると、セキュリティ アクションはクラスまたはメソッドが公開するホスト リソースに基づいてリンク確認要求を作成します。

重要

この属性の目的は、セキュリティ動作ではなく、ホスト固有のプログラミング モデルのガイドラインを強制することです。 リンク確認要求はプログラミング モデルの要件への準拠を確認するために使われますが、HostProtectionAttribute はセキュリティ アクセス許可ではありません。

ホストにプログラミング モデルの要件がない場合、リンク確認要求は発生しません。

この属性は次のものを識別します。

  • ホスト プログラミング モデルには適合しないが、それ以外の問題はないメソッドまたはクラス。

  • ホスト プログラミング モデルに適合せず、サーバーが管理するユーザー コードが不安定になる可能性があるメソッドまたはクラス。

  • ホスト プログラミング モデルに適合せず、サーバー プロセス自体が不安定になる可能性があるメソッドまたはクラス。

Note

ホストで保護された環境で実行する可能性のあるアプリケーションによって呼び出されるクラス ライブラリを作成する場合は、HostProtectionResource リソース カテゴリを公開するメンバーにこの属性を適用する必要があります。 この属性を持つ .NET Framework クラス ライブラリのメンバーについては、直前の呼び出し元だけがチェックされます。 カスタムのライブラリ メンバーについても、同じように直前の呼び出し元がチェックされるようにする必要があります。

注意

Ngen.exe (ネイティブ イメージ ジェネレーター) を使用して、 によって保護されているアセンブリのネイティブ イメージをHostProtectionAttribute作成しないでください。 完全信頼環境では、 に関係なくイメージが常に HostProtectionAttribute読み込まれ、部分信頼環境ではイメージは読み込まれません。

コンストラクター

HostProtectionAttribute()
古い.

HostProtectionAttribute クラスの新しいインスタンスを既定値で初期化します。

HostProtectionAttribute(SecurityAction)
古い.

指定した SecurityAction 値を使用して、HostProtectionAttribute クラスの新しいインスタンスを初期化します。

プロパティ

Action
古い.

セキュリティ アクションを取得または設定します。

(継承元 SecurityAttribute)
ExternalProcessMgmt
古い.

外部プロセス管理が公開されているかどうかを示す値を取得または設定します。

ExternalThreading
古い.

外部スレッド処理が公開されているかどうかを示す値を取得または設定します。

MayLeakOnAbort
古い.

操作が終了した場合にリソースがメモリをリークする可能性があるかどうかを示す値を取得または設定します。

Resources
古い.

ホストに害を及ぼす可能性がある機能のカテゴリを指定するフラグを取得または設定します。

SecurityInfrastructure
古い.

セキュリティ インフラストラクチャが公開されているかどうかを示す値を取得または設定します。

SelfAffectingProcessMgmt
古い.

自己作用型のプロセス管理が公開されているかどうかを示す値を取得または設定します。

SelfAffectingThreading
古い.

自己作用型のスレッド処理が公開されているかどうかを示す値を取得または設定します。

SharedState
古い.

共有状態が公開されているかどうかを示す値を取得または設定します。

Synchronization
古い.

同期が公開されているかどうかを示す値を取得または設定します。

TypeId
古い.

派生クラスで実装されると、この Attribute の一意の識別子を取得します。

(継承元 Attribute)
UI
古い.

ユーザー インターフェイスが公開されているかどうかを示す値を取得または設定します。

Unrestricted
古い.

属性によって保護されているリソースに対して完全な (無制限の) アクセス許可が宣言されているかどうかを示す値を取得または設定します。

(継承元 SecurityAttribute)

メソッド

CreatePermission()
古い.

新しいホスト保護のアクセス許可を作成して返します。

Equals(Object)
古い.

このインスタンスが、指定されたオブジェクトと等価であるかどうかを示す値を返します。

(継承元 Attribute)
GetHashCode()
古い.

このインスタンスのハッシュ コードを返します。

(継承元 Attribute)
GetType()
古い.

現在のインスタンスの Type を取得します。

(継承元 Object)
IsDefaultAttribute()
古い.

派生クラスでオーバーライドされるとき、このインスタンスの値が派生クラスの既定値であるかどうかを示します。

(継承元 Attribute)
Match(Object)
古い.

派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。

(継承元 Attribute)
MemberwiseClone()
古い.

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()
古い.

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)
古い.

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

(継承元 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)
古い.

オブジェクトの型情報を取得します。この情報はインターフェイスの型情報の取得に使用できます。

(継承元 Attribute)
_Attribute.GetTypeInfoCount(UInt32)
古い.

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

(継承元 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)
古い.

オブジェクトによって公開されたプロパティおよびメソッドへのアクセスを提供します。

(継承元 Attribute)

適用対象

こちらもご覧ください