IApplicationTrustManager.DetermineApplicationTrust Methode

Definitie

Bepaalt of een toepassing moet worden uitgevoerd en welke set machtigingen aan de toepassing moet worden verleend.

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

Parameters

activationContext
ActivationContext

De activeringscontext voor de toepassing.

context
TrustManagerContext

De vertrouwensbeheercontext voor de toepassing.

Retouren

Een object dat beveiligingsbeslissingen over de toepassing bevat.

Voorbeelden

In het volgende voorbeeld ziet u een implementatie van de DetermineApplicationTrust methode voor een aangepast vertrouwensmanager. Dit codevoorbeeld maakt deel uit van een groter voorbeeld voor de IApplicationTrustManager interface.

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

Opmerkingen

De DetermineApplicationTrust methode wordt aangeroepen door de host om te bepalen of een toepassing moet worden uitgevoerd en welke set machtigingen moet worden verleend. DetermineApplicationTrust retourneert een ApplicationTrust object met een DefaultGrantSet eigenschap die een machtigingenset bevat die de machtigingen vertegenwoordigt die moeten worden verleend aan elke assembly die wordt uitgevoerd binnen de context van de toepassing. De verleende machtigingen zijn niet van toepassing op assembly's in de globale assemblycache. Het ApplicationTrust object heeft ook een IsApplicationTrustedToRun eigenschap die de vertrouwensmanager instelt om aan te geven of de toepassing moet worden vertrouwd. Als de vertrouwensbeheerder aangeeft dat de toepassing kan worden vertrouwd, activeert de host de toepassing en verleent de bijbehorende assembly's de set machtigingen die zijn opgegeven in de ApplicationTrust verzameling.

Van toepassing op