Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS7 & Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule registering problems

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?

like image 553
Mr. Flibble Avatar asked Sep 30 '09 15:09

Mr. Flibble


People also ask

What is iis7 used for?

IIS 7 and above is the product name used to refer to the versions of Internet Information Services (IIS) that are included in some editions of Windows Server® 2008, Windows Server® 2008 R2, Windows Vista®, and Windows® 7. IIS 7.0 is the Web Server (IIS) role in Windows Server 2008, and the Web server in Windows Vista.

Is IIS 8.5 Vulnerable?

A vulnerability was found in Microsoft IIS 7.0/7.5/8.0/8.5/10 (Web Server). It has been classified as problematic.

How do I open iis7?

On the Start menu, click All Programs, click Accessories, and then click Run. In the Run text box, type control panel, and then click OK. In the Control Panel window, click Classic View, and then double-click Administrative Tools. In the Administrative Tools window, double-click Internet Information Services.


2 Answers

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

like image 174
Xorsat Avatar answered Oct 15 '22 13:10

Xorsat


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

like image 23
kzfabi Avatar answered Oct 15 '22 13:10

kzfabi