在使用MEF加载DLL的System.Security.Permissions.FileIOPermission [英] System.Security.Permissions.FileIOPermission when using MEF to load dll's

查看:558
本文介绍了在使用MEF加载DLL的System.Security.Permissions.FileIOPermission的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图加载ASP.NET MVC应用程序中的一些dll的成MEF DirectoryCatalog:

I am trying to load some dll's into a MEF DirectoryCatalog within an ASP.NET MVC application:

var catalog = new DirectoryCatalog(HttpRuntime.BinDirectory, "Toptable.Mobile.*.dll");

当我运行通过卡西尼Web服务器应用程序(即F5)一切都托管在IIS时运行正常不过(7)我得到了以下异常:

When I run the app through the Cassini web server (i.e. F5) everything runs fine however when hosted in IIS(7) I get the following exception:

[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessPermission.Demand() +54
   System.IO.Path.GetFullPath(String path) +193
   System.ComponentModel.Composition.Hosting.DirectoryCatalog.GetFullPath(String path) +267
   System.ComponentModel.Composition.Hosting.DirectoryCatalog.Initialize(String path, String searchPattern) +144
   System.ComponentModel.Composition.Hosting.DirectoryCatalog..ctor(String path, String searchPattern) +166
   Toptable.Mobile.MvcApplication.Application_Start() in C:\Dev\Toptable\Toptable.Mobile\Toptable.Mobile.Web\Global.asax.cs:74

该应用程序的.NET信任级别设置为完全无论对于网站和全球。我将在web.config中(的System.Web /信任),以完全的信任级别。暗战什么可以导致它的想法。有什么建议?

The .NET trust levels for the application are set to "Full" both for the site and globally and I have set the trust level in web.config (system.web/trust) to Full. Running out of ideas about what could be causing it. Any suggestions?

推荐答案

例外使它看起来像你实际上并没有在完​​全信任运行。检查 AppDomain.IsFullyTrusted 属性来验证你是。如果你是,那么这可能是因为ASP.NET在IIS下运行的OS用户与权限降低的情况下,并没有权限调用GetFullPath。作为一种变通方法,你可以自己扫描目录,每个DLL创建一个AssemblyCatalog,并添加所有的AssemblyCatalogs的成AggregateCatalog。

The exception makes it look like you aren't actually running in full trust. Check the AppDomain.IsFullyTrusted property to verify that you are. If you are, then it may be the case that ASP.NET is running as an OS user with reduced privileges under IIS, and it doesn't have permission to call GetFullPath. As a workaround you could scan the directory yourself, create an AssemblyCatalog for each DLL, and add all of the AssemblyCatalogs into an AggregateCatalog.

这篇关于在使用MEF加载DLL的System.Security.Permissions.FileIOPermission的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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