Export (0) Print
Expand All

IApplicationTrustManager Interface

Note: This interface is new in the .NET Framework version 2.0.

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)

[ComVisibleAttribute(true)] 
public interface IApplicationTrustManager : ISecurityEncodable
/** @attribute ComVisibleAttribute(true) */ 
public interface IApplicationTrustManager extends ISecurityEncodable
ComVisibleAttribute(true) 
public interface IApplicationTrustManager extends ISecurityEncodable

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.

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>

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");
		}
	}
}

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

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

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft