本文整理汇总了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");
}
}
}