IApplicationTrustManager.DetermineApplicationTrust Metod

Definition

Avgör om ett program ska köras och vilken uppsättning behörigheter som ska beviljas till det.

public:
 System::Security::Policy::ApplicationTrust ^ DetermineApplicationTrust(ActivationContext ^ activationContext, System::Security::Policy::TrustManagerContext ^ context);
public System.Security.Policy.ApplicationTrust DetermineApplicationTrust(ActivationContext activationContext, System.Security.Policy.TrustManagerContext context);
abstract member DetermineApplicationTrust : ActivationContext * System.Security.Policy.TrustManagerContext -> System.Security.Policy.ApplicationTrust
Public Function DetermineApplicationTrust (activationContext As ActivationContext, context As TrustManagerContext) As ApplicationTrust

Parametrar

activationContext
ActivationContext

Aktiveringskontexten för programmet.

context
TrustManagerContext

Förtroendehanterarens kontext för programmet.

Returer

Ett objekt som innehåller säkerhetsbeslut om programmet.

Exempel

I följande exempel visas en implementering av DetermineApplicationTrust metoden för en anpassad förtroendehanterare. Det här kodexemplet är en del av ett större exempel som tillhandahålls för IApplicationTrustManager gränssnittet.

public ApplicationTrust DetermineApplicationTrust(ActivationContext appContext, TrustManagerContext context)
{
    ApplicationTrust trust = new ApplicationTrust(appContext.Identity);
    trust.IsApplicationTrustedToRun = false;

    ApplicationSecurityInfo asi = new ApplicationSecurityInfo(appContext);
    trust.DefaultGrantSet = new PolicyStatement(asi.DefaultRequestSet, PolicyStatementAttribute.Nothing);
    if (context.UIContext == TrustManagerUIContext.Run)
    {
        string message = "Do you want to run " + asi.ApplicationId.Name + " ?";
        string caption = "MyTrustManager";
        MessageBoxButtons buttons = MessageBoxButtons.YesNo;
        DialogResult result;

        // Displays the MessageBox.

        result = MessageBox.Show(message, caption, buttons);

        if (result == DialogResult.Yes)
        {
            trust.IsApplicationTrustedToRun = true;
            if (context != null)
                trust.Persist = context.Persist;
            else
                trust.Persist = false;
        }
    }

    return trust;
}
Public Function DetermineApplicationTrust(ByVal appContext As ActivationContext, ByVal context As TrustManagerContext) As ApplicationTrust Implements IApplicationTrustManager.DetermineApplicationTrust
    Dim trust As New ApplicationTrust(appContext.Identity)
    trust.IsApplicationTrustedToRun = False

    Dim asi As New ApplicationSecurityInfo(appContext)
    trust.DefaultGrantSet = New PolicyStatement(asi.DefaultRequestSet, _
    PolicyStatementAttribute.Nothing)
    If context.UIContext = TrustManagerUIContext.Run Then
        Dim message As String = "Do you want to run " + asi.ApplicationId.Name + " ?"
        Dim caption As String = "MyTrustManager"
        Dim buttons As MessageBoxButtons = MessageBoxButtons.YesNo
        Dim result As DialogResult

        ' Displays the MessageBox.
        result = MessageBox.Show(message, caption, buttons)

        If result = DialogResult.Yes Then
            trust.IsApplicationTrustedToRun = True
            If Not (context Is Nothing) Then
                trust.Persist = context.Persist
            Else
                trust.Persist = False
            End If
        End If
    End If
    Return trust

End Function 'DetermineApplicationTrust

Kommentarer

Metoden DetermineApplicationTrust anropas av värden för att avgöra om ett program ska köras och vilken uppsättning behörigheter det ska beviljas. DetermineApplicationTrust returnerar ett ApplicationTrust objekt med en DefaultGrantSet egenskap som innehåller en behörighetsuppsättning som representerar de behörigheter som ska beviljas till varje sammansättning som körs i programmets kontext. De beviljade behörigheterna gäller inte för sammansättningar i den globala sammansättningscacheminnet. Objektet ApplicationTrust har också en IsApplicationTrustedToRun egenskap som förtroendehanteraren anger för att ange om programmet ska vara betrott. Om förtroendehanteraren anger att programmet kan vara betrott aktiverar värden programmet och beviljar dess sammansättningar den uppsättning behörigheter som anges i ApplicationTrust samlingen.

Gäller för