【问题标题】:StructureMap, IIS 7.5 and FileIOExceptionStructureMap、IIS 7.5 和 FileIOException
【发布时间】:2010-12-09 13:00:12
【问题描述】:

大家好。我正在尝试解决一个显然并不少见的问题,但我不确定如何为人们解决这个问题。当我通过 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/)、in the comments on this blog posta year or so ago on the structuremap mailing list 提出。

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

更新 因此,这不可能是解决问题的最佳方法,但在四处挖掘并查看 Joshua 提到的内容之后,我必须做这些事情才能让它工作:StructureMap, Code Access Security and a Bad Solution to a Problem。更好的解决方案将不胜感激。

【问题讨论】:

  • 如已接受的答案中所述,处理此问题的方法原来是 StructureMap 中的代码更改。无需更改 IIS 配置。

标签: iis structuremap .net-3.5


【解决方案1】:

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

我没有使用 XML 配置,所以我在配置代码中添加了以下行,从而解决了问题。

IgnoreStructureMapConfig = true;

【讨论】:

    【解决方案2】:

    在带有 IIS 7.5 的 Windows 7 上使用官方的 StructureMap 2.5.4 构建,我仍然遇到了这个问题。 马略克的变化

      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)解决了这个问题。

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

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

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

        【讨论】:

        • 我使用的是 2.5.3 版。我没有从源代码构建它。
        猜你喜欢
        • 2011-11-11
        • 2011-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多