HostProtectionAttributeとは? わかりやすく解説

HostProtectionAttribute クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

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

名前空間: System.Security.Permissions
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class
 Or AttributeTargets.Struct Or AttributeTargets.Constructor
 Or AttributeTargets.Method Or AttributeTargets.Delegate, AllowMultiple:=True, Inherited:=False)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class
 HostProtectionAttribute
    Inherits CodeAccessSecurityAttribute
Dim instance As HostProtectionAttribute
[SerializableAttribute] 
[AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method|AttributeTargets.Delegate,
 AllowMultiple=true, Inherited=false)] 
[ComVisibleAttribute(true)] 
public sealed class HostProtectionAttribute
 : CodeAccessSecurityAttribute
[SerializableAttribute] 
[AttributeUsageAttribute(AttributeTargets::Assembly|AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Constructor|AttributeTargets::Method|AttributeTargets::Delegate,
 AllowMultiple=true, Inherited=false)] 
[ComVisibleAttribute(true)] 
public ref class HostProtectionAttribute sealed
 : public CodeAccessSecurityAttribute
/** @attribute SerializableAttribute() */ 
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method|AttributeTargets.Delegate,
 AllowMultiple=true, Inherited=false) */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class HostProtectionAttribute
 extends CodeAccessSecurityAttribute
SerializableAttribute 
AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method|AttributeTargets.Delegate,
 AllowMultiple=true, Inherited=false) 
ComVisibleAttribute(true) 
public final class HostProtectionAttribute
 extends CodeAccessSecurityAttribute
解説解説

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

メモ重要 :

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

ホストプログラミング モデル要件設定されていない場合、リンク確認要求発生しません。

この属性は、次のメソッドまたはクラス識別します。

使用例使用例

各種HostProtectionResource 値を持つ HostProtectionAttribute 属性使用するコード例次に示します

Imports System
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

<Assembly: SecurityPermissionAttribute(SecurityAction.RequestMinimum, _
    ControlAppDomain:=True)> 
<Assembly: SecurityPermissionAttribute(SecurityAction.RequestMinimum, _
    Execution:=True)> 

' 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 'Exit

    ' 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 'ExecuteBreak

    ' 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 'WatchFileEvents

    ' 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 'StartThread

    ' 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 'OnChanged
End Class 'HostProtectionExample
 

' 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 'New

    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 'Dispose
End Class 'MyControl
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;
[assembly:SecurityPermissionAttribute(SecurityAction.RequestMinimum, ControlAppDomain
 = true)]
[assembly:SecurityPermissionAttribute(SecurityAction.RequestMinimum, Execution =
 true)]

// 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;
            }
        }
    }
}
#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.

[assembly:SecurityPermissionAttribute(SecurityAction::RequestMinimum,ControlAppDomain=true)];
[assembly:SecurityPermissionAttribute(SecurityAction::RequestMinimum,Execution=true)];
[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();
}

継承階層継承階層
System.Object
   System.Attribute
     System.Security.Permissions.SecurityAttribute
       System.Security.Permissions.CodeAccessSecurityAttribute
        System.Security.Permissions.HostProtectionAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

HostProtectionAttribute コンストラクタ ()


HostProtectionAttribute コンストラクタ

HostProtectionAttribute クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
HostProtectionAttribute () HostProtectionAttribute クラス新しインスタンス既定値初期化します。
HostProtectionAttribute (SecurityAction) 指定した SecurityAction 値を使用してHostProtectionAttribute クラス新しインスタンス初期化します。
参照参照

関連項目

HostProtectionAttribute クラス
HostProtectionAttribute メンバ
System.Security.Permissions 名前空間

HostProtectionAttribute コンストラクタ (SecurityAction)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

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

名前空間: System.Security.Permissions
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    action As SecurityAction _
)
Dim action As SecurityAction

Dim instance As New HostProtectionAttribute(action)
public HostProtectionAttribute (
    SecurityAction action
)
public:
HostProtectionAttribute (
    SecurityAction action
)
public HostProtectionAttribute (
    SecurityAction action
)
public function HostProtectionAttribute (
    action : SecurityAction
)

パラメータ

action

SecurityAction 値の 1 つ

例外例外
例外種類条件

ArgumentException

action が LinkDemand ではありません。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HostProtectionAttribute クラス
HostProtectionAttribute メンバ
System.Security.Permissions 名前空間

HostProtectionAttribute プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Action  セキュリティ アクション取得または設定します。 ( SecurityAttribute から継承されます。)
パブリック プロパティ ExternalProcessMgmt 外部プロセス管理公開されているかどうかを示す値を取得または設定します
パブリック プロパティ ExternalThreading 外部スレッド処理が公開されているかどうかを示す値を取得または設定します
パブリック プロパティ MayLeakOnAbort 操作終了した場合リソースメモリリークする可能性があるかどうかを示す値を取得または設定します
パブリック プロパティ Resources ホストに害を及ぼす可能性がある機能カテゴリ指定するフラグ取得または設定します
パブリック プロパティ SecurityInfrastructure セキュリティ インフラストラクチャ公開されているかどうかを示す値を取得または設定します
パブリック プロパティ SelfAffectingProcessMgmt 自己作用型のプロセス管理公開されているかどうかを示す値を取得または設定します
パブリック プロパティ SelfAffectingThreading 自己作用型のスレッド処理が公開されているかどうかを示す値を取得または設定します
パブリック プロパティ SharedState 共有状態が公開されているかどうかを示す値を取得または設定します
パブリック プロパティ Synchronization 同期公開されているかどうかを示す値を取得または設定します
パブリック プロパティ TypeId  派生クラス実装されている場合は、この Attribute一意識別子取得します。 ( Attribute から継承されます。)
パブリック プロパティ UI ユーザー インターフェイス公開されているかどうかを示す値を取得または設定します
パブリック プロパティ Unrestricted  属性によって保護されているリソースに対して完全な (無制限の) アクセス許可宣言されているかどうかを示す値を取得または設定します。 ( SecurityAttribute から継承されます。)
参照参照

関連項目

HostProtectionAttribute クラス
System.Security.Permissions 名前空間

その他の技術情報

属性使用したメタデータ拡張
プロセスへのランタイム読み込み
リンク確認要求

HostProtectionAttribute メソッド


パブリック メソッドパブリック メソッド

  名前 説明
パブリック メソッド CreatePermission オーバーライドされます新しホスト保護アクセス許可作成して返します
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用され指定した型のカスタム属性取得します。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されカスタム属性配列取得します。 ( Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスハッシュ コード返します。 ( Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラス既定値かどうか示します。 ( Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます指定した型のカスタム属性が、アセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されているかどうか判断します。 ( Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンス等しかどうかを示す値を返します。 ( Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String返します。 ( Object から継承されます。)
参照参照

関連項目

HostProtectionAttribute クラス
System.Security.Permissions 名前空間

その他の技術情報

属性使用したメタデータ拡張
プロセスへのランタイム読み込み
リンク確認要求

HostProtectionAttribute メンバ

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

HostProtectionAttribute データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド HostProtectionAttribute オーバーロードされます。 HostProtectionAttribute クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Action  セキュリティ アクション取得または設定します。(SecurityAttribute から継承されます。)
パブリック プロパティ ExternalProcessMgmt 外部プロセス管理公開されているかどうかを示す値を取得または設定します
パブリック プロパティ ExternalThreading 外部スレッド処理が公開されているかどうかを示す値を取得または設定します
パブリック プロパティ MayLeakOnAbort 操作終了した場合リソースメモリリークする可能性があるかどうかを示す値を取得または設定します
パブリック プロパティ Resources ホストに害を及ぼす可能性がある機能カテゴリ指定するフラグ取得または設定します
パブリック プロパティ SecurityInfrastructure セキュリティ インフラストラクチャ公開されているかどうかを示す値を取得または設定します
パブリック プロパティ SelfAffectingProcessMgmt 自己作用型のプロセス管理公開されているかどうかを示す値を取得または設定します
パブリック プロパティ SelfAffectingThreading 自己作用型のスレッド処理が公開されているかどうかを示す値を取得または設定します
パブリック プロパティ SharedState 共有状態が公開されているかどうかを示す値を取得または設定します
パブリック プロパティ Synchronization 同期公開されているかどうかを示す値を取得または設定します
パブリック プロパティ TypeId  派生クラス実装されている場合は、この Attribute一意識別子取得します。(Attribute から継承されます。)
パブリック プロパティ UI ユーザー インターフェイス公開されているかどうかを示す値を取得または設定します
パブリック プロパティ Unrestricted  属性によって保護されているリソースに対して完全な (無制限の) アクセス許可宣言されているかどうかを示す値を取得または設定します。(SecurityAttribute から継承されます。)
パブリック メソッドパブリック メソッド
  名前 説明
パブリック メソッド CreatePermission オーバーライドされます新しホスト保護アクセス許可作成して返します
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用され指定した型のカスタム属性取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されカスタム属性配列取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスハッシュ コード返します。 (Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラス既定値かどうか示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます指定した型のカスタム属性が、アセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されているかどうか判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンス等しかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String返します。 (Object から継承されます。)
参照参照

関連項目

HostProtectionAttribute クラス
System.Security.Permissions 名前空間

その他の技術情報

属性使用したメタデータ拡張
プロセスへのランタイム読み込み
リンク確認要求



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「HostProtectionAttribute」の関連用語

HostProtectionAttributeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HostProtectionAttributeのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS