Share via


HostProtectionAttribute.SecurityInfrastructure プロパティ

定義

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

public:
 property bool SecurityInfrastructure { bool get(); void set(bool value); };
public bool SecurityInfrastructure { get; set; }
[System.Runtime.InteropServices.ComVisible(true)]
public bool SecurityInfrastructure { get; set; }
member this.SecurityInfrastructure : bool with get, set
[<System.Runtime.InteropServices.ComVisible(true)>]
member this.SecurityInfrastructure : bool with get, set
Public Property SecurityInfrastructure As Boolean

プロパティ値

セキュリティ インフラストラクチャが公開されている場合は true。それ以外の場合は false。 既定値は、false です。

属性

次のコード例は、 プロパティで 属性を使用する HostProtectionAttribute 方法を SecurityInfrastructure 示しています。 この例は、 クラスに対して提供される大きな例の HostProtectionAttribute 一部です。

// 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;
}
// 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;
}
' 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

注釈

オブジェクトを WindowsIdentity 使用してユーザーを偽装することは、セキュリティ インフラストラクチャを公開する例です。

適用対象

こちらもご覧ください