HostProtectionAttribute.SecurityInfrastructure Eigenschaft

Definition

Ruft einen Wert ab, der angibt, ob die Sicherheitsinfrastruktur verfügbar gemacht wird, oder legt diesen fest.

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

Eigenschaftswert

Boolean

true, wenn die Sicherheitsinfrastruktur verfügbar gemacht wird; andernfalls false. Der Standardwert ist false.

Attribute

Beispiele

Im folgenden Codebeispiel wird die Verwendung des HostProtectionAttribute Attributs mit der SecurityInfrastructure Eigenschaft veranschaulicht. In diesem Beispiel wird ein größeres Beispiel für die HostProtectionAttribute Klasse bereitgestellt.

// 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

Hinweise

Die Verwendung eines Objekts zum Identitätswechsel eines WindowsIdentity Benutzers ist ein Beispiel für die Exposierung der Sicherheitsinfrastruktur.

Gilt für

Siehe auch