IApplicationTrustManager.DetermineApplicationTrust 方法

定义

确定是否应执行应用程序以及应授予它哪个权限集。

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

参数

activationContext
ActivationContext

应用程序的激活上下文。

context
TrustManagerContext

信任应用程序上下文的管理器。

返回

一个对象,包含有关应用程序的安全决策。

示例

以下示例演示自定义信任管理器的 DetermineApplicationTrust 方法的实现。 此代码示例是为 接口提供的更大示例的 IApplicationTrustManager 一部分。

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

注解

方法 DetermineApplicationTrust 由主机调用,以确定是否应执行应用程序以及应向其授予哪一组权限。 DetermineApplicationTrust 返回具有 ApplicationTrust 属性的 对象 DefaultGrantSet ,该属性包含一个权限集,该权限集表示要授予在应用程序上下文中执行的每个程序集的权限。 授予的权限不适用于全局程序集缓存中的程序集。 对象 ApplicationTrust 还具有一个 IsApplicationTrustedToRun 属性,信任管理器设置该属性以指示应用程序是否应受信任。 如果信任管理器指示应用程序可以受信任,主机将激活应用程序,并向其程序集授予集合中 ApplicationTrust 提供的权限集。

适用于