IApplicationTrustManager.DetermineApplicationTrust(ActivationContext, TrustManagerContext) Método

Definição

Determina se um aplicativo deve ser executado e qual conjunto de permissões deve ser concedido a ele.Determines whether an application should be executed and which set of permissions should be granted to it.

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

Parâmetros

activationContext
ActivationContext

O contexto de ativação para o aplicativo.The activation context for the application.

context
TrustManagerContext

O contexto do gerenciador de confiança para o aplicativo.The trust manager context for the application.

Retornos

ApplicationTrust

Um objeto que contém decisões de segurança sobre o aplicativo.An object that contains security decisions about the application.

Exemplos

O exemplo a seguir mostra uma implementação do DetermineApplicationTrust método para um Gerenciador de confiança personalizado.The following example shows an implementation of the DetermineApplicationTrust method for a custom trust manager. Este exemplo de código faz parte de um exemplo maior fornecido para a IApplicationTrustManager interface.This code example is part of a larger example provided for the 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

Comentários

O DetermineApplicationTrust método é chamado pelo host para determinar se um aplicativo deve ser executado e qual conjunto de permissões ele deve ser concedido.The DetermineApplicationTrust method is called by the host to determine whether an application should be executed and which set of permissions it should be granted. DetermineApplicationTrust Retorna um ApplicationTrust objeto com uma DefaultGrantSet propriedade que contém um conjunto de permissões que representa as permissões a serem concedidas a cada assembly em execução dentro do contexto do aplicativo.DetermineApplicationTrust returns an ApplicationTrust object with a DefaultGrantSet property that contains a permission set representing the permissions to be granted to each assembly executing within the context of the application. As permissões concedidas não se aplicam a assemblies no cache de assembly global.The granted permissions do not apply to assemblies in the global assembly cache. O ApplicationTrust objeto também tem uma IsApplicationTrustedToRun propriedade que o Gerenciador de confiança define para indicar se o aplicativo deve ser confiável.The ApplicationTrust object also has an IsApplicationTrustedToRun property that the trust manager sets to indicate whether the application should be trusted. Se o Gerenciador de confiança indicar que o aplicativo pode ser confiável, o host ativará o aplicativo e concederá a seus assemblies o conjunto de permissões fornecido na ApplicationTrust coleção.If the trust manager indicates that the application can be trusted, the host activates the application and grants its assemblies the set of permissions provided in the ApplicationTrust collection.

Aplica-se a