**Description**: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
**Exception Details**: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
此问题出现在SO(https://stackoverflow.com/questions/784666/),in the comments on this blog post和a year or so ago on the structuremap mailing list。
我的问题不是在外部托管环境中运行它。我甚至不能让它在我自己的盒子上运行(IIS 7.5,Win7 RC,.NET 3.5)。我试图将站点配置为使用自定义策略文件,并且FileIOPermission被标记为具有不受限制的访问权限...没有骰子。如果有人有一些提示或链接,将不胜感激。
更新 因此,这不是解决问题的最佳方法,但在深入探讨约书亚所提到的内容后,这些是我必须做的事情才能让它发挥作用:StructureMap, Code Access Security and a Bad Solution to a Problem。我们将不胜感激。
答案 0 :(得分:2)
对于它的价值,我遇到了同样的问题,我可以完全控制该框,甚至将所有权限设置为完全信任。使用IIS 7.5,我不得不将用于特定应用程序池的标识更改为NetworkService而不是ApplicationPoolIdentity。一旦我重新启动IIS,它就可以工作。
答案 1 :(得分:1)
仅供参考,我正在使用StructureMap v2.6.1并遇到了这个问题。
我不使用XML配置,因此我在配置代码中添加了以下行,解决了问题。
IgnoreStructureMapConfig = true;
答案 2 :(得分:0)
这是一个错误,并已在主干中修复。它将包含在2.6+版本中。 一些早期版本的StructureMap会尝试不必要地将动态程序集写入磁盘,或者不必要地尝试从文件系统中读取。
如果您在不允许访问文件系统(ASP.NET)中的完整路径的受限环境中运行,请确保在配置容器时设置IgnoreDefaultFile = true。请记住,这将禁用从StructureMap.config加载XML配置的功能。
答案 3 :(得分:0)
使用IIS 7.5上的官方StructureMap 2.5.4构建在Windows 7上我仍遇到此问题。 Mallioch的变化
ObjectFactory.Initialize(x =>
{
x.UseDefaultStructureMapConfigFile = false;
x.IgnoreStructureMapConfig = true;
是解决FileIOPermission
例外所必需的,但之后我收到了Request for the permission of type ‘System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ failed.
,我使用Mike的解决方案解决了这个问题(我为此创建了step-by-step visualization)。