5

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?

Liam
  • 27,717
  • 28
  • 128
  • 190
Mr. Flibble
  • 26,564
  • 23
  • 69
  • 100
  • 1
    PerWebRequestLifestyleModule is a module, not a handler. Remove it from the handlers section. – Mauricio Scheffer Sep 30 '09 at 15:09
  • Try including the Version, Culture and PublicKeyToken in the module declaration. – Mauricio Scheffer Sep 30 '09 at 15:15
  • Thanks, I removed the module declaration. The Version, Culture and PublicKeyToken weren't necessary. I also had to add as a handler. Also had to create the directory 'C:\TempImageFiles' to get it working. – Mr. Flibble Sep 30 '09 at 18:53
  • So did it solve your problem? And what does ChartImageHandler have to do with Windsor? – queen3 Sep 30 '09 at 20:42
  • Heh heh. Looks like I confused myself there. I was having problems with both Castle and ChartImageHandler - looks like I thought I had asked about ChartImageHandler in my question when I commented. Anywhoo - yes, my problem is solved. – Mr. Flibble Oct 01 '09 at 12:14
  • 3
    Possible duplicate of [Looks like you forgot to register the http module with Windsor Castle with IIS7](http://stackoverflow.com/questions/258011/looks-like-you-forgot-to-register-the-http-module-with-windsor-castle-with-iis7) – Liam Oct 14 '15 at 08:33

3 Answers3

6

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

Xorsat
  • 2,388
  • 21
  • 21
4

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()

Liam
  • 27,717
  • 28
  • 128
  • 190
kzfabi
  • 2,065
  • 1
  • 22
  • 26
1

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...

Jacob
  • 21
  • 5