我有一些代碼,動態編譯一個Razor模板到一個程序集中,我使用 執行一組權限(無法訪問文件等)。限制許可AppDomain授權集問題
這適用於我們的開發計算機和我們的測試服務器(Windows 2008 IIS7 x64 .NET 4)。但是,我們的生產服務器上(同一規格),它給人的錯誤:
:
這裏是代碼「加載此程序集將產生不同的補助金,其他情況下設置(從HRESULT異常0x80131401)。」 -
public static SandboxContext Create(string pathToUntrusted, List<Assembly> references)
{
AppDomainSetup adSetup = new AppDomainSetup();
adSetup.ShadowCopyFiles = "true";
var dir = new DirectoryInfo(pathToUntrusted);
String tempPath = Path.Combine(Path.GetTempPath(), dir.Name + "_shadow");
adSetup.CachePath = tempPath;
// Our sandbox needs access to this assembly.
string AccessPath = Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "bin\\CommonInterfaces.WebPages.dll");
System.IO.File.Copy(AccessPath, Path.Combine(pathToUntrusted, "CommonInterfaces.WebPages.dll"), true);
var baseDir = Path.GetFullPath(pathToUntrusted);
adSetup.ApplicationBase = baseDir;
adSetup.PrivateBinPath = baseDir;
adSetup.PartialTrustVisibleAssemblies =
new string[] {
typeof(System.Web.WebPageTraceListener).Assembly.FullName,
typeof(System.Web.Razor.RazorEngineHost).Assembly.FullName};
//Setting the permissions for the AppDomain. We give the permission to execute and to
//read/discover the location where the untrusted code is loaded.
PermissionSet permSet = new PermissionSet(PermissionState.None);
permSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
//We want the sandboxer assembly's strong name, so that we can add it to the full trust list.
StrongName fullTrustAssembly = typeof(Sandboxer).Assembly.Evidence.GetHostEvidence<StrongName>();
Evidence evidence = new Evidence();
//Now we have everything we need to create the AppDomain, so let's create it.
AppDomain newDomain = AppDomain.CreateDomain("Sandbox", evidence, adSetup, permSet, fullTrustAssembly);
ObjectHandle handle = Activator.CreateInstanceFrom(
newDomain, typeof(Sandboxer).Assembly.ManifestModule.FullyQualifiedName,
typeof(Sandboxer).FullName
);
//Unwrap the new domain instance into a reference in this domain and use it to execute the
//untrusted code.
var newDomainInstance = (Sandboxer)handle.Unwrap();
return new SandboxContext(newDomain, newDomainInstance);
}
任何想法,爲什麼它會在一臺服務器上不同?我只是在破損的服務器上安裝了所有優秀的Windows Update,並沒有幫助。
如果我改變的PermissionSet到: -
PermissionSet permSet = new PermissionSet(PermissionState.Unrestricted);
所有的代碼工作(但出現安全漏洞推測)