IIS7 & Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule registering problems

若如初见. 提交于 2019-12-22 06:35:41

问题


UPDATE:

In Windsor 2.5 the assembly name is Castle.Windsor not Castle.MicroKernel


I'm trying to deploy an ASP.NET MVC app to IIS7 and I'm getting this error:

Looks like you forgot to register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule Add '' to the section on your web.config

My httpModules contains:

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

system.webServer handlers section contains

<handlers>
  <remove name="PerRequestLifestyle"/>
  <add name="PerRequestLifestyle" preCondition="managedHandler" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Microkernel" verb="*" path="*.castle" />
</handlers>

I added the verb="*" path="*.castle" part as I was getting errors when they were missing. Not sure if their values are correct.

Anyone know what the problem is here?


回答1:


You can solve the problem by registering the HTTP module in configuration/system.webServer/modules instead of configuration/system.web/httpModules.




回答2:


My problem was that I was bootstraping the container in Application_Start, Modules are not initialized at that point in ASP.NET so when you try to register/use PerWebRequest Lifestyle it throws that Exception because it detects that the module was not initialized.

I ended up using this library from Castle Contrib which provides the HybridPerWebRequestTransient Lifestyle which if not initialized at the moment uses the Transient Lifestyle.

You just have to download the library (as zip is ok) open the Solution and compile it, grab the generated DLL and reference it in your project.

If you are using Castle.Windsor version over 3.0 you will have to remove current reference to it and add the reference to the version you are using (I was using 3.1 and did not have any problems).

This is the code to use the Lifestyle: .LifeStyle.HybridPerWebRequestTransient()




回答3:


Took me some time to find a solution for this but all I had to was update the dll being referneced in the web.config...

Using Castle.Core and Windsor 2.5.1...



来源:https://stackoverflow.com/questions/1498722/iis7-castle-microkernel-lifestyle-perwebrequestlifestylemodule-registering-pro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!