Search code examples
asp.net.netiishttpmodule

Sharing an HttpModule between multiple sub-applications without the GAC


I have a website setup in IIS with one web.config set at the root for many sub-application virtuals (about 35), some of which use their own unique overrides/configurations.

I have two HttpModules that I would like to implement for all of the sub-apps at once. Without using the GAC, is there a way to specify the implementation in web.config so that these modules can apply to all sub-apps without re-compiling module code into each sub-application? Can I store the HttpModule assembly somewhere in the site structure that it can be utilized by all sub-apps?


Solution

  • It is possible to register a http module in the root web.config (system.webServer/modules section). The module must have a strong name (must be signed):

    <add name="MyModule" preCondition="managedHandler" type="MyModule.Namespace, MyModuleAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bfd166351ed997df" />
    

    Now IIS expects that the module is in the bin directory (or in GAC). dependentAssembly section instructs IIS where can be the assembly file found:

       <runtime>
            <assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1">
                <dependentAssembly>
                    <assemblyIdentity name="MyModuleAssembly" publicKeyToken="bfd166351ed997df"/>
                    <codeBase version="1.0.0.0"
                              href="file://c:/SharedLibs/MyModuleAssembly.dll" />
                </dependentAssembly>
            </assemblyBinding>
        </runtime>