代码之家  ›  专栏  ›  技术社区  ›  simendsjo

不允许在安全服务器上运行的asp.net mvc2中使用反射?

  •  1
  • simendsjo  · 技术社区  · 14 年前

    我试图在一个安全的服务器上部署一个网站,但是我在反射方面遇到了问题。 我想这和安全有关,但我不太确定。

    ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
       System.Reflection.Module._GetTypesInternal(StackCrawlMark& stackMark) +0
       System.Reflection.Assembly.GetTypes() +105
    

    如果忽略这些异常并继续从程序集加载,则不会加载任何内容。似乎我根本不允许在任何程序集上执行此操作。当我在一个不安全的web服务器上运行时,一切正常。我对IIS、mvc或.net安全策略了解不多,因此,如果您能提供正确的帮助,我将不胜感激。

    以下是导致异常的代码:

    private static IEnumerable<IModule> GetModules()
    {
        foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
        {
            foreach (var type in assembly.GetTypes()) // <--- This one throws
            {
                var moduleType = type.GetInterface(typeof(IModule).Name);
                if (moduleType != null)
                {
                    IModule module = null;
                    try
                    {
                        module = (IModule)Activator.CreateInstance(type, null);
                    }
                    catch (ReflectionTypeLoadException ex)
                    {
                        // GetInterface() get's all interfaces with the same
                        // name, so we'll just skip those who isn't ours
                        logger.Warn("Could not load module", ex);
                    }
    
                    if( module != null)
                        yield return module;
                }
            }
        }
    }
    
    1 回复  |  直到 14 年前
        1
  •  1
  •   simendsjo    14 年前

    我发现了错误。它与HTTP/HTTP s根本没有关系。

    http://forums.asp.net/t/1196710.aspx

    依赖模块中的某些程序集未复制到输出文件夹。我的开发机器和测试服务器在GAC中有这些,所以一切都在那里工作。

    我显式地添加了这些组件,现在一切都正常了。

    谢谢你的时间