Friday, September 18, 2009

IIS Modules and Handlers - One web.config for Both IIS 6 and IIS 7

I recently started running my development projects on IIS 7 when I upgraded to Windows 7. I initially created a separate copy of the web.config with modified settings for the <httpHandlers> and <httpModules> sections as these need to move with IIS 7. In IIS 6 the <httpHandlers> and <httpModules> sections are located within the <system.web> section of the web.config file. However, with IIS 7 they need to be configured in the <system.webServer> section. So I did just that, I moved and modified those sections so that I could run in an Integrated App Pool. Please read How to Take Advantage of the IIS 7.0 Integrated Pipeline for more details on the differences between running in Integrated versus Classic mode.

However, I was recently looking into the ELMAH (Error Logging Modules and Handlers) Project and noticed in their demo application that they had thoroughly documented the IIS 6 and IIS 7 settings in their web.config and found this cool little comment:

    The <system.webServer> section is required for running ELMAH under Internet
    Information Services 7.0. It is not necessary for previous version of IIS.
    In general, it would be best to include it for all .NET Framework 2.0 and above
    configurations in order to have a more portable solution between various
    versions of IIS.

    IIS 5.x, IIS 6 require the modules and handlers to be declared in <system.web>
    whereas IIS 7 needs them declared here and complains if they are in fact
    declared in <system.web>. Fortunately, the
    <validation validateIntegratedModeConfiguration="false" /> entry tells IIS 7
    not to worry about the modules and handlers declared in <system.web>.

    If you only ever want to use IIS 7, then do the following:
    1. Remove handlers and modules from <system.web>
    2. Remove the <validation validateIntegratedModeConfiguration="false" /> element

So I did a little research (Google search) on validateIntegratedModeConfiguration and found this MSDN Article on ValidationSection Class [IIS 7] that explains how this works.

Therefore, since myself and the other developers are still running a mixture of IIS 5.1 (Windows XP) and IIS 7 (Windows 7) I am going to update our shared web.config so that we no longer need to maintain separate versions of the web.config file for the different IIS versions, but can use one common one. This will make things a lot simpler. Then once we are all running on IIS 7, as well as all of our downstream environments, we can turn this off and remove the <httpHandlers> and <httpModules> entries in the <system.web> section.

No comments: