Csharp/CSharp Tutorial/Security/Evidence — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 15:31, 26 мая 2010

Create Evidence

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Security;
using System.Security.AccessControl;
using System.Security.Policy;
using System.Security.Permissions;
using System.Security.Principal;
using System.Text;
using System.Threading;
public class MainClass
{
    public static void Main()
    {
        AppDomain sandboxAd;
        Evidence ev = new Evidence();
        ev.AddAssembly(Assembly.GetExecutingAssembly());
        PermissionSet permSet = new PermissionSet(PermissionState.None);
        permSet.AddPermission(new SecurityPermission(PermissionState.Unrestricted));
        permSet.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
        permSet.AddPermission(new ReflectionPermission(PermissionState.Unrestricted));
        sandboxAd = AppDomain.CreateDomain("Sandbox", ev, new AppDomainSetup(), permSet);
        
    }
}

Get the Evidence collection from the loaded assembly and Display the Host Evidence

using System;
using System.Reflection;
using System.Collections;
using System.Security.Policy;
public class MainClass
{
    public static void Main(string[] args) 
    {
        Assembly a = Assembly.LoadFrom(args[0]);
        Evidence e = a.Evidence;
        
        IEnumerator x = e.GetHostEnumerator();
        Console.WriteLine("host evidence collection:");
        while(x.MoveNext()) 
        {
            Console.WriteLine(x.Current.ToString());
        }
    }
}