This documentation is archived and is not being maintained.

IApplicationTrustManager Interface

Updated: August 2009

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

Namespace:  System.Security.Policy
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
<ComVisibleAttribute(True)> _
Public Interface IApplicationTrustManager _
	Inherits ISecurityEncodable
'Usage
Dim instance As IApplicationTrustManager

Trust managers must implement the IApplicationTrustManager interface. The host calls the DetermineApplicationTrust method in the trust manager to determine whether an application should be executed and which permissions should be granted to the application.

In the .NET Framework 3.5 SP1, there is only one trust manager, which can be a custom implementation of the IApplicationTrustManager interface. The default trust manager implementation prompts the user for permission to install the application and elevate the permissions granted to the application. Other trust manager implementations might have different user experiences. For example, an implementation might check an enterprise list for trusted applications instead of prompting the user for that information.

The following code example shows a very 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" ?> 
'<configuration> 
'    <mscorlib> 
'        <security> 
'            <policy> 
'                <ApplicationSecurityManager> 
'                    <ApplicationEntries /> 
'                    <IApplicationTrustManager class="MyNamespace.MyTrustManager, CustomTrustManager, Version=1.0.0.3, Culture=neutral, PublicKeyToken=5659fc598c2a503e"/> 
'                </ApplicationSecurityManager> 
'            </policy> 
'        </security> 
'    </mscorlib> 
'</configuration> 
Imports System
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 'FromXml 
End Class 'MyTrustManager

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

Date

History

Reason

August 2009

Added information to Remarks about trust managers.

Customer feedback.

Show: