本文整理匯總了C#中System.AppDomain.IsFullyTrusted屬性的典型用法代碼示例。如果您正苦於以下問題:C# AppDomain.IsFullyTrusted屬性的具體用法?C# AppDomain.IsFullyTrusted怎麽用?C# AppDomain.IsFullyTrusted使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.AppDomain
的用法示例。
在下文中一共展示了AppDomain.IsFullyTrusted屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
namespace SimpleSandboxing
{
public class Worker : MarshalByRefObject
{
static void Main()
{
Worker w = new Worker();
w.TestIsFullyTrusted();
AppDomain adSandbox = GetInternetSandbox();
w = (Worker) adSandbox.CreateInstanceAndUnwrap(
typeof(Worker).Assembly.FullName,
typeof(Worker).FullName);
w.TestIsFullyTrusted();
}
public void TestIsFullyTrusted()
{
AppDomain ad = AppDomain.CurrentDomain;
Console.WriteLine("\r\nApplication domain '{0}': IsFullyTrusted = {1}",
ad.FriendlyName, ad.IsFullyTrusted);
Console.WriteLine(" IsFullyTrusted = {0} for the current assembly",
typeof(Worker).Assembly.IsFullyTrusted);
Console.WriteLine(" IsFullyTrusted = {0} for mscorlib",
typeof(int).Assembly.IsFullyTrusted);
}
// ------------ Helper method ---------------------------------------
static AppDomain GetInternetSandbox()
{
// Create the permission set to grant to all assemblies.
System.Security.Policy.Evidence hostEvidence = new System.Security.Policy.Evidence();
hostEvidence.AddHostEvidence(new System.Security.Policy.Zone(
System.Security.SecurityZone.Internet));
System.Security.PermissionSet pset =
System.Security.SecurityManager.GetStandardSandbox(hostEvidence);
// Identify the folder to use for the sandbox.
AppDomainSetup ads = new AppDomainSetup();
ads.ApplicationBase = System.IO.Directory.GetCurrentDirectory();
// Create the sandboxed application domain.
return AppDomain.CreateDomain("Sandbox", hostEvidence, ads, pset, null);
}
}
}
輸出:
Application domain 'Example.exe': IsFullyTrusted = True IsFullyTrusted = True for the current assembly IsFullyTrusted = True for mscorlib Application domain 'Sandbox': IsFullyTrusted = False IsFullyTrusted = False for the current assembly IsFullyTrusted = True for mscorlib