27

我在我的一个 MVC 项目中使用了 Windsor DI 框架。当我尝试从 Visual Studio 2008 运行时,该项目运行良好。

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

看起来您忘记注册 http 模块 Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule 添加 '<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel" />' 到您网站上的部分。配置

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

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

4

5 回答 5

47

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

我试图解决自定义路由类处理,但类型 for已注册IService为. 路由子系统停留在 Web 请求的更高级别,并且对象在路由处理时不存在。Application_StartIServicePerWebRequestLifestyle

于 2011-02-11T11:12:08.723 回答
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>
于 2008-11-03T07:30:24.870 回答
4

它帮助了我:

<system.web>
  <httpModules>
      <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
  </httpModules>
</system.web>
于 2010-11-14T20:59:55.683 回答
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>
于 2011-10-05T18:38:09.853 回答
0

我写了一篇博客文章,通过反编译 Castle.Windsor.dll 在代码级别解释了这个问题。

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

于 2016-05-25T00:05:20.477 回答