首页 文章

看起来你忘了在 Windsor Castle 和 IIS7 上注册 http 模块

提问于
浏览
26

我在我的一个 MVC 项目中使用 windsor DI 框架。当我尝试从 Visual Studio 2008 运行时,该项目工作正常。

但是,当我尝试在 IIS7 中运行创建应用程序的项目时,我收到以下错误消息:

您似乎忘了注册 http 模块 Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule 将“<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel" />”添加到 web.config 的部分

但是这个模块已经存在于 web.config 文件的 httpmodule 部分中。

有谁知道我必须做些什么来消除这个问题。

5 回答

  • 35

    尝试将其添加到system.webServer部分?

    <configuration>
        <system.web>
            <httpModules>
                <add name="PerRequestLifestyle" type="..." />
            </httpModules>
        </system.web>
        <system.webServer>
            <modules>
                <add name="PerRequestLifestyle" type="..." />
            </modules>
        </system.webServer>
    </configuration>
    
  • 45

    我有同样的错误,但它是由另一个原因引起的:

    我试图在Application_Start处解决IService以进行自定义路由类处理,但IService的类型已在PerWebRequestLifestyle中注册。路由子系统保持在 Web 请求的更高级别,并且路由处理时不存在对象。

  • 4

    它帮助了我:

    <system.web>
      <httpModules>
          <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
      </httpModules>
    
  • 3

    我在开发环境中遇到过这个问题。值得注意的是这个标签:

    <validation validateIntegratedModeConfiguration="false"/>
    

    虽然它显然在锡上做了它所说的,它可以阻止那些讨厌的错误出现。假设您的其余配置工作正常。

    什么对我有用:

    <system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
      <modules runAllManagedModulesForAllRequests="true">
        <remove name="PerRequestLifestyle"/>
        <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor"/>
      </modules>
    </system.webServer>
    
  • 0

    我写了一篇博文,通过反编译 Castle.Windsor.dll 来解释 code-level 中的问题。

    修复和解释:忘记注册 http 模块 Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule

相关问题