The other day I dumped into troubles getting an ASP.NET web application to work after migrating it from .NET 2.0 to .NET 4.0. It turned out that the problem was not bound to the .NET version but instead to the Managed Pipeline Mode settings in IIS7.
Before the migration to .NET 4.0 the application run as a .NET v2.0 Classic application pool and everything was running smoothly. The application uses a custom HttpModule for NHibernate session and transaction management, configured in web.config. All SQL CRUD stuff worked fine but the updates misfired after the upgrade.
What?
Luckily the problem could be reproduced in the test environment, using the same configuration as the the production. I debugged the application on my development workstation, using the Visual Studio built in Cassini web server, but I could not get anything to misfire. I decided to configure a web site on my local IIS7. Debugging the application I noticed that I never hit the breakpoints set in the custom HttpModule. Since NHibernate is used in the HttpModule I was more or less sure that it was NHibernate causing the strange behaviour…
The solution
After some googling I found this, NHibernate HTTPModule, and it turned out that the problem was not at all caused by NHibernate. When using IIS7 and Integrated Managed Pipeline Mode the HttpModules have to be configured/declared in the system.webServer node in web.config instead of the system.web node as before when using Classic mode. The following code, more or less stolen from the page referred to above shows what to do:
<configuration>
<!-- Old config, using Classic mode application pool -->
<system.web>
<httpModules>
<add name="MyCustomHttpModule" type="MyNamespave.TheHttpModule, HttpModuleAssembly"/>
</httpModules>
<httpHandlers>
<!-- No custom handlers here for this application -->
</httpHandlers>
</system.web>
<!-- New config, using Integrated mode application pool -->
<system.webServer>
<modules>
<add name="MyCustomHttpModule" type="MyNamespave.TheHttpModule, HttpModuleAssembly"/>
</modules>
<handlers>
<!-- If custom handlers are used, they should be declared here -->
</handlers>
</system.webServer>
</configuration>
After changing this, everything started working. Thank you Martin Willey!