Прочетете на английски Редактиране

Споделяне чрез


IApplicationTrustManager.DetermineApplicationTrust Method

Definition

Determines whether an application should be executed and which set of permissions should be granted to it.

C#
public System.Security.Policy.ApplicationTrust DetermineApplicationTrust(ActivationContext activationContext, System.Security.Policy.TrustManagerContext context);

Parameters

activationContext
ActivationContext

The activation context for the application.

context
TrustManagerContext

The trust manager context for the application.

Returns

An object that contains security decisions about the application.

Examples

The following example shows an implementation of the DetermineApplicationTrust method for a custom trust manager. This code example is part of a larger example provided for the IApplicationTrustManager interface.

C#
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;
}

Remarks

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 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. The granted permissions do not apply to assemblies in the global assembly cache. The ApplicationTrust object also has an IsApplicationTrustedToRun property that the trust manager sets to indicate whether the application should be trusted. 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.

Applies to

Продукт Версии
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1