HostProtectionAttribute.SecurityInfrastructure Proprietà

Definizione

Ottiene o imposta un valore che indica se viene esposta l'infrastruttura di sicurezza.

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

Valore della proprietà

Boolean

true se viene esposta l'infrastruttura di sicurezza; in caso contrario, false. Il valore predefinito è false.

Attributi

Esempio

Nell'esempio di codice seguente viene illustrato l'uso dell'attributo HostProtectionAttribute con la SecurityInfrastructure proprietà . Questo esempio fa parte di un esempio più grande fornito per la HostProtectionAttribute classe.

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

Commenti

L'uso di un oggetto per rappresentare un WindowsIdentity utente è un esempio di esposizione dell'infrastruttura di sicurezza.

Si applica a

Vedi anche