加载具有受限特权的程序集 [英] Loading An Assemble with restricted privileges

查看:55
本文介绍了加载具有受限特权的程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了Microsoft实验书(70-536)实验6.3中的所有步骤.

我的问题是以下代码:


I have done all the steps in my Microsoft Lab book (70-536) Lab 6.3

My problem is with the following code:


static void Main(string[] args)
        {
            MainClass objMain = new MainClass();
            Console.WriteLine("----VERIFYING TRUST LEVEL ----");
            objMain.FindPermissionLevel();
            Console.Read();

        }




我查看了MSDN,找不到用于MainClass正常工作的程序集引用,示例中也没有定义类"MainClass",这是本书中的示例:




I looked on MSDN and could not find an assembly reference to get MainClass to work, also there was no class ''MainClass'' defined in the example, here is the example right out of the book:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//using System.Collections.Generic;
using System.Reflection;
using System.Security;
using System.Security.Policy;

using System.Collections;


namespace WorkingOnApplicationDomainPrivileges
{
    class Program
    {
        static void Main(string[] args)
        {
            MainClass objMain = new MainClass();
            Console.WriteLine("----VERIFYING TRUST LEVEL ----");
            objMain.FindPermissionLevel();
            Console.Read();

        }

        private void FindPermissionLevel()
        {
            bool isFullTrust = true;
            IEnumerator policy = SecurityManager.PolicyHierarchy();
            while (policy.MoveNext())
            {
                PolicyLevel currentLevel = (PolicyLevel)policy.Current;
                CodeGroup codeGrp = currentLevel.ResolveMatchingCodeGroups(Assembly.GetExecutingAssembly().Evidence);

                isFullTrust = IsFullTrustPolicyLevel(codeGrp, currentLevel);

                if (isFullTrust)
                {
                    Console.WriteLine("/t Policy Level: " + currentLevel.Label + " - Full trust mode");
                }
                else
                {
                    Console.WriteLine("/t Policy Level: " + currentLevel.Label + " - Not in trust mode");
                }
            }
        }

        private bool IsFullTrustPolicyLevel(CodeGroup group, PolicyLevel level)
        {
            bool success = false;
            NamedPermissionSet nps = level.GetNamedPermissionSet(group.PermissionSetName);

            if (nps.Name == "FullTrust")
            {
                success = true;
            }
            else
            {
                success = false;
            }

            return success;
        }
    }
}




我的问题是我应该如何维护MainClass才能使其正常工作?

ps这是在控制台应用程序中完成的.

这些书中有很多错误,其中一些我能够解决自己,而其余的我只有CodeProject值得感谢.
微软和出版社Wiley都不对这些书的低质量提供支持.

在此先感谢...




My question is how do I wright a MainClass to get this to work?

ps this is done in a console application.

There have been so many errors in these books, some of which I was able to solve myself, as for the rest I have only CodeProject to thank.
Both Microsoft, and the publishing house Wiley provide no support for the poor quality of these books.

Thanks in advance...

推荐答案

找到了解决方法:

更改行:

Found the solution:

change the line:

MainClass objMain = new MainClass();



为了匹配应用程序MainClass的名称,在本例中为"Program",这是默认名称:



To match the name of the MainClass of the application, in this case "Program" which is the default name:

Program objMain = new Program();



谢谢...



thanks...


这本书是否提供下载代码的网站?也许您可以这样做,而不用手动输入所有内容.如果它*提供*下载站点,则下载的代码*应*包含允许代码编译所需的所有内容.
Does the book offer a site to download the code? Maybe you can do that instead of typing everything in manually. If it *does* provide a download site, the downloaded code *should* contain everything required to allow the code to compile.


这篇关于加载具有受限特权的程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆