Why can event handlers only be bound to HttpApplication events during IHttpModule initialization?
This is just another "working in dev server, why not working in IIS" type question.
I 开发者_Go百科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?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.
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)
If it does work in your development environment, not on your IIS, chances are that your are (were?) using Cassini dev server. This server is far from having the same behavior than IIS.
An other solution is to use IIS Express instead, which provide the same level of integration in Visual Studio (at least starting from 2010) than old Cassini dev server, while behaving far more like IIS. IIS Express has a standalone installer available at Microsoft web site, and is also included in most recent versions of Visual Studio.
That is for the "why" on your first question line.
As for why it is forbidden to bound events outside of an IHttpModule initialization, I do not know.
精彩评论