你好。我试图解决一个显然并不罕见的问题,我不知道如何找到这个问题是如何解决的。当我通过IIS在我的机器上运行StructureMap时,我得到一个例外,它看起来像这样:

**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/ ),< a href =“http://codebetter.com/blogs/jeremy.miller/archive/2008/11/30/a-gentle-quickstart-for-structuremap-2-5.aspx”rel =“nofollow noreferrer”> in此博客文章的评论和上的rel =“nofollow noreferrer”。

我的问题不是在外部托管环境中运行它。我甚至不能让它在我自己的盒子上运行(IIS 7.5,Win7 RC,.NET 3.5)。我试图将站点配置为使用自定义策略文件,并且FileIOPermission被标记为具有不受限制的访问权限...没有骰子。如果有人有一些提示或链接,将不胜感激。

<强>更新 因此,这是解决问题的最佳方法,但是在深入探讨约书亚提到的内容之后,这些是我必须要做的事情才能让它发挥作用: StructureMap,Code Access安全性和解决问题的不良解决方案。我们将不胜感激。

有帮助吗?

解决方案

这是一个错误,并已在主干中修复。它将包含在2.6+版本中。 一些早期版本的StructureMap会尝试不必要地将动态程序集写入磁盘,或者不必要地尝试从文件系统中读取。

如果您在不允许访问文件系统(ASP.NET)中的完整路径的受限环境中运行,请确保在配置容器时设置IgnoreDefaultFile = true。请记住,这将禁用从StructureMap.config加载XML配置的功能。

其他提示

为了它的价值,我遇到了同样的问题,我完全控制了盒子,甚至将所有权限设置为完全信任。使用IIS 7.5,我不得不将用于特定应用程序池的标识更改为NetworkService而不是ApplicationPoolIdentity。一旦我重新启动IIS,它就可以工作。

仅供参考,我正在使用StructureMap v2.6.1并遇到了这个问题。

我不使用XML配置,因此我在配置代码中添加了以下行,解决了问题。

IgnoreStructureMapConfig = true;

使用IIS 7.5上的官方StructureMap 2.5.4构建在Windows 7上我仍遇到此问题。 Mallioch的变化

  ObjectFactory.Initialize(x =>
    {
      x.UseDefaultStructureMapConfigFile = false;
      x.IgnoreStructureMapConfig = true;

是解决 FileIOPermission 异常所必需的,但后来我收到了请求的类型&#8216; System.Web.AspNetHostingPermission,System,Version = 2.0.0.0,Culture =中性,PublicKeyToken = b77a5c561934e089&#8242;失败。我使用迈克的解决方案(我为此创建了一个逐步可视化)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top