IApplicationTrustManager IApplicationTrustManager IApplicationTrustManager IApplicationTrustManager Interface

Definition

Bestimmt, ob eine Anwendung ausgeführt werden soll, und welcher Berechtigungssatz dieser Anwendung gewährt werden soll.Determines whether an application should be executed and which set of permissions should be granted to it.

public interface class IApplicationTrustManager : System::Security::ISecurityEncodable
[System.Runtime.InteropServices.ComVisible(true)]
public interface IApplicationTrustManager : System.Security.ISecurityEncodable
type IApplicationTrustManager = interface
    interface ISecurityEncodable
Public Interface IApplicationTrustManager
Implements ISecurityEncodable
Attribute
Implementiert

Beispiele

Das folgende Beispiel zeigt eine einfache Implementierung von IApplicationTrustManager.The following example shows a simple implementation of IApplicationTrustManager.

// To use the custom trust manager MyTrustManager, compile it into CustomTrustManager.dll, 
// place that assembly in the GAC, and  put the following elements in
// an ApplicationTrust.config file in the config folder in the Microsoft .NET framework
// installation folder.

//<?xml version="1.0" encoding="utf-8" ?>
//                    <ApplicationEntries />
//                    <IApplicationTrustManager class="MyNamespace.MyTrustManager, CustomTrustManager, Version=1.0.0.3, Culture=neutral, PublicKeyToken=5659fc598c2a503e"/>

using System;
using System.Security;
using System.Security.Policy;
using System.Windows.Forms;
namespace MyNamespace
{
    public class MyTrustManager : 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 SecurityElement ToXml()
        {
            SecurityElement se = new SecurityElement("IApplicationTrustManager");
            se.AddAttribute("class", typeof(MyTrustManager).AssemblyQualifiedName);
            return se;
        }

        public void FromXml(SecurityElement se)
        {
            if (se.Tag != "IApplicationTrustManager" || (string)se.Attributes["class"] != typeof(MyTrustManager).AssemblyQualifiedName)
                throw new ArgumentException("Invalid tag");
        }
    }
}
' To use the custom trust manager MyTrustManager, compile it into CustomTrustManager.dll, 
' place that assembly in the GAC, and  put the following elements in
' an ApplicationTrust.config file in the config folder in the Microsoft .NET framework
' installation folder.
'<?xml version="1.0" encoding="utf-8" ?>
'                    <ApplicationEntries />
'                    <IApplicationTrustManager class="MyNamespace.MyTrustManager, CustomTrustManager, Version=1.0.0.3, Culture=neutral, PublicKeyToken=5659fc598c2a503e"/>
Imports System.Security
Imports System.Security.Policy
Imports System.Windows.Forms


Public Class MyTrustManager
    Implements IApplicationTrustManager
    
    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
    
    Public Function ToXml() As SecurityElement Implements IApplicationTrustManager.ToXml
        Dim se As New SecurityElement("IApplicationTrustManager")
        se.AddAttribute("class", GetType(MyTrustManager).AssemblyQualifiedName)
        Return se

    End Function 'ToXml
    
    Public Sub FromXml(ByVal se As SecurityElement) Implements IApplicationTrustManager.FromXml
        If se.Tag <> "IApplicationTrustManager" OrElse _
        CStr(se.Attributes("class")) <> GetType(MyTrustManager).AssemblyQualifiedName Then
            Throw New ArgumentException("Invalid tag")
        End If

    End Sub
End Class

Hinweise

Trust-Manager müssen die IApplicationTrustManager -Schnittstelle implementieren.Trust managers must implement the IApplicationTrustManager interface. Der Host ruft die IApplicationTrustManager.DetermineApplicationTrust -Methode auf, um zu bestimmen, ob eine Anwendung ausgeführt werden soll und welche Berechtigungen der Anwendung erteilt werden sollen.The host calls the IApplicationTrustManager.DetermineApplicationTrust method to determine whether an application should be executed and which permissions should be granted to the application.

In und höher gibt es nur einen Vertrauensstellungs-Manager, bei dem es sich um eine Benutzer IApplicationTrustManager definierte Implementierung der-Schnittstelle handeln kann. .NET Framework 4.NET Framework 4In the .NET Framework 4.NET Framework 4 and later, there is only one trust manager, which can be a custom implementation of the IApplicationTrustManager interface. Die Standard Implementierung von Trust Manager fordert den Benutzer zur Eingabe der Berechtigung auf, die Anwendung zu installieren und die Berechtigungen zu erhöhen, die der Anwendung erteilt wurden.The default trust manager implementation prompts the user for permission to install the application and to elevate the permissions granted to the application. Andere Trust-Manager-Implementierungen können unterschiedliche Benutzeroberflächen bereitstellen.Other trust manager implementations might provide different user experiences. Eine-Implementierung kann beispielsweise eine Unternehmens Liste nach vertrauenswürdigen Anwendungen überprüfen, anstatt den Benutzer zur Eingabe dieser Informationen aufzufordern.For example, an implementation might check an enterprise list for trusted applications instead of prompting the user for that information.

Methoden

DetermineApplicationTrust(ActivationContext, TrustManagerContext) DetermineApplicationTrust(ActivationContext, TrustManagerContext) DetermineApplicationTrust(ActivationContext, TrustManagerContext) DetermineApplicationTrust(ActivationContext, TrustManagerContext)

Bestimmt, ob eine Anwendung ausgeführt werden soll, und welcher Berechtigungssatz dieser Anwendung gewährt werden soll.Determines whether an application should be executed and which set of permissions should be granted to it.

FromXml(SecurityElement) FromXml(SecurityElement) FromXml(SecurityElement) FromXml(SecurityElement)

Stellt ein Sicherheitsobjekt mit einem angegebenen Zustand aus einer XML-Codierung wieder her.Reconstructs a security object with a specified state from an XML encoding.

(Inherited from ISecurityEncodable)
ToXml() ToXml() ToXml() ToXml()

Erstellt eine XML-Codierung des Sicherheitsobjekts und seines aktuellen Zustands.Creates an XML encoding of the security object and its current state.

(Inherited from ISecurityEncodable)

Gilt für: