3

我有一个 MVC4 webapi 控制器。它没有无参数的构造函数。所以,我使用 Windsor 依赖解析器,在 System.Web.Http.WebHost 下工作时一切正常。但是,当我尝试使用 HttpSelfHostServer 时,我收到异常消息:

Looks like you forgot to register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule To fix this add <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" /> to the <httpModules> section on your web.config. If you plan running on IIS in Integrated Pipeline mode, you also need to add the module to the <modules> section under <system.webServer>. Alternatively make sure you have Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 assembly in your GAC (it is installed by ASP.NET MVC3 or WebMatrix) and Windsor will be able to register the module automatically without having to add anything to the config file. 显然,windsor di 无法注册他的 HttpModule。我试图添加

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

在我的 app.config 中,没有运气。尝试 WebActivator 使用 PreApplicationStart 方法也没有运气。有什么方法可以为自托管 webapi 应用程序添加 httpModule 吗?

4

1 回答 1

7

自托管时不能使用 HttpModules。它们是 ASP.NET 特定的功能。

于 2012-08-06T16:09:37.620 回答