Exemple #1
0
        public static void TesteSecurityTransparent()
        {
            //create  the AppDomainSetup
            AppDomainSetup info = new AppDomainSetup();

            //set the path to the assembly to load.
            info.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            //create the domain
            AppDomain domain = AppDomain.CreateDomain(
                "CasHostDemo", null, info, GetPermissionSet());
            //create an instance of the AssemblyInfo class
            Type         t      = typeof(AssemblyInfo);
            ObjectHandle handle = Activator.CreateInstanceFrom(
                domain,
                t.Assembly.ManifestModule.FullyQualifiedName,
                t.FullName);
            AssemblyInfo ai = (AssemblyInfo)handle.Unwrap();

            Console.WriteLine("DOMAIN INFO:\n");
            //get the domain info
            Console.WriteLine(GetDomainInfo(domain));

            Console.WriteLine("ASSEMBLY INFO:\n");
            //get the assembly info form the sandboxed assembly
            Console.WriteLine(ai.GetCasSecurityAttributes());
        }
Exemple #2
0
        //[SecurityCritical]
        public static void TesteNoGAC()
        {
            //create the AppDomainSetup
            AppDomainSetup info = new AppDomainSetup();

            //set the path to the assembly to load.
            info.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            Assembly   a     = Assembly.LoadFile(Path.Combine(info.ApplicationBase, "CAS_01.dll"));
            StrongName sName = a.Evidence.GetHostEvidence <StrongName>();
            //StrongName fullTrustAssembly = typeof(AssemblyInfo).Assembly.Evidence.GetHostEvidence<StrongName>();
            //create the domain
            AppDomain domain = AppDomain.CreateDomain(
                "CasHostDemo", null, info, GetPermissionSet(), new StrongName[] { sName });

            //create an instance of the AseemblyInfo class
            Type         t      = typeof(AssemblyInfo);
            ObjectHandle handle = Activator.CreateInstanceFrom(
                domain,
                t.Assembly.ManifestModule.FullyQualifiedName,
                t.FullName);
            AssemblyInfo ai = (AssemblyInfo)handle.Unwrap();

            Console.WriteLine("DOMAIN INFO:\n");
            //get the domain info
            Console.WriteLine(GetDomainInfo(domain));

            Console.WriteLine("ASSEMBLY INFO:\n");
            //get the assembly info form the sandboxed assembly
            Console.WriteLine(ai.GetCasSecurityAttributes());
        }