1

嘿伙计们,我试图弄清楚我需要什么权限才能允许我在 appdomain 中运行 ironpython,但拒绝读写权限以及互联网权限。

这是我的 IronPython 课程:

public class PBLPython
{

    private static ScriptEngine pyEngine;
    private static ScriptRuntime pyRuntime;
    public ScriptScope pyScope { get; private set; }

    public PBLPython(String [] args)
    {

        String pyCodePath = "PATH";

        pyEngine = Python.CreateEngine();
        pyScope = pyEngine.CreateScope();
        dynamic Scope = pyScope;

        Scope.appy = this;

        pyEngine.ExecuteFile(pyCodePath, pyScope);

        foreach (String s in args)
        {
            pyEngine.Execute(s, pyScope);
        }

    } 
}

这是我创建appdomain的类

class PythonDomain
{
    private static AppDomain pyDomain;
    public PythonDomain()
    {

        AppDomain root = AppDomain.CurrentDomain;
        String pyCodePath = @"PATH";
        String AppCodePath = @"PATH";
        AppDomainSetup setup = new AppDomainSetup();
        setup.ApplicationBase = AppCodePath;

        Evidence e = new Evidence();

        e.AddHostEvidence(new Zone(SecurityZone.Intranet));
        e.AddHostEvidence(new ApplicationDirectory(AppCodePath));


        System.Security.PermissionSet ps =
            new PermissionSet(PermissionState.None);
        ps.AddPermission(new FileIOPermission(FileIOPermissionAccess.AllAccess, pyCodePath));
        ps.AddPermission(new FileIOPermission(FileIOPermissionAccess.AllAccess, AppCodePath));
        ps.AddPermission(new UIPermission(PermissionState.Unrestricted));

        PermissionSet permSet = SecurityManager.GetStandardSandbox(e);

        StrongName[] fullTrustAssemblies = new StrongName[5];
        fullTrustAssemblies[0] = typeof(PBLPython).Assembly.Evidence.GetHostEvidence<StrongName>();
        fullTrustAssemblies[1] = typeof(ScriptEngine).Assembly.Evidence.GetHostEvidence<StrongName>();
        fullTrustAssemblies[2] = typeof(ScriptRuntime).Assembly.Evidence.GetHostEvidence<StrongName>();
        fullTrustAssemblies[3] = typeof(ScriptScope).Assembly.Evidence.GetHostEvidence<StrongName>();
        fullTrustAssemblies[4] = 

        pyDomain = AppDomain.CreateDomain("PythonDomain", e, setup, ps, fullTrustAssemblies);

        pyDomain.ExecuteAssemblyByName(@"ConsoleApplication1", @"print('hellz yea')");

        AppDomain.Unload(pyDomain);



    }

现在,由于我的 ironpython 中的这行代码,我得到了一个通用的安全异常

Scope.appy = this;

如果我将它更改为我没有创建的东西,比如说对象,它会完美运行。有人可以向我指出我缺少什么许可,或者我正在尝试做的事情是不可能的吗?

4

0 回答 0