本文整理匯總了C#中System.Security.Policy.IApplicationTrustManager接口的典型用法代碼示例。如果您正苦於以下問題:C# IApplicationTrustManager接口的具體用法?C# IApplicationTrustManager怎麽用?C# IApplicationTrustManager使用的例子?那麽, 這裏精選的接口代碼示例或許可以為您提供幫助。
IApplicationTrustManager接口屬於System.Security.Policy命名空間,在下文中一共展示了IApplicationTrustManager接口的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DetermineApplicationTrust
// 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");
}
}
}