StructureMap、IIS 7.5和FileIOException

5

大家好。我正在尝试解决一个似乎很常见的问题,但不知道如何找到解决方案。当我通过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 post),以及大约一年前在structuremap邮件列表上出现过(a 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配置更改。 - Mallioch
4个回答

2

就我所知,我也遇到了这个问题,尽管我对服务器有完全的控制权并将所有权限设置为完全信任。在使用IIS 7.5时,我不得不更改特定应用程序池使用的身份标识为NetworkService而不是ApplicationPoolIdentity。一旦我重新启动了IIS,它就正常工作了。


1

我使用的是StructureMap v2.6.1,并遇到了这个问题。

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

IgnoreStructureMapConfig = true;

0

在Windows 7上使用官方StructureMap 2.5.4版本,并且在IIS 7.5上仍然遇到了这个问题。 Mallioch的更改

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

需要解决FileIOPermission异常,但随后我收到了请求类型为‘System.Web.AspNetHostingPermission,System,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089’的权限失败。我使用Mike的解决方案解决了这个问题(我已经创建了一个逐步可视化)。


0

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

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


我正在使用版本2.5.3。我没有从源代码构建它。 - Mallioch

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接