views:

207

answers:

2

This is just another "working in dev server, why not working in IIS" type question.

I created a nice DAL using NHibernate as described here. When creating an ISession, I hook up an event handler to the HttpApplication.EndRequest to take care of cleaning it up.

However, I deployed my site to IIS and it says:

Event handlers can only be bound to HttpApplication events during IHttpModule initialization.

I completely understand what the message is saying, but I can't undestrand why.

I can subscribe to a Button's event in any time, why can't I subscribe to an event of the HttpApplication?

I would be very grateful if someone could shed some light on this.

And I also wonder, why is it working with the development server and not with IIS 7?

EDIT: Now that two months has passed, I still haven't received any useful answers. :(
Is this issue really that hard?

A: 

You're trying to use the HttpApplication outside its initialization pipeline. Just don't do it. As the error says, bind your events during IHttpModule initialization.

Mauricio Scheffer
That much I get. The part I'm missing is why. :)
Venemo
+1  A: 

Because IIS7 has some changes of how the HTTP Application is launched (basically, the worker process associated and the HTTP Application thereof).

Have a look at http://n2cms.codeplex.com/Thread/View.aspx?ThreadId=38311.

If you run IIS7 in classic mode or in integrated mode with the following items in web.config, it should work fine:

<configuration>
   <system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
   </system.webServer>
</configuration>

(Snipped from http://code.google.com/p/n2cms/source/browse/trunk/src/wwwroot/Web.config)

MasterGaurav
I already have validateIntegratedModeConfiguration="false" (MVC put it in there by default), but it is not working.
Venemo