IIS Fails to Load Custom HTTP Module from web.config in ASP.NET MVC3: Configuration and Debugging Guide


3 views

Working with custom HTTP modules in ASP.NET MVC3 can be particularly frustrating when they work perfectly in the VS development server but fail silently in IIS. This behavior typically indicates one of several configuration issues in the IIS pipeline.



  
    
  




  
    
  

1. Verify the assembly is properly deployed to the bin folder
2. Check the application pool pipeline mode (Classic vs Integrated)
3. Ensure the module registration is in the correct configuration section
4. Confirm the type string is fully qualified and correct

// Module implementation example
public class MyHttpModule : IHttpModule
{
    public void Init(HttpApplication context)
    {
        context.BeginRequest += OnBeginRequest;
    }

    private void OnBeginRequest(object sender, EventArgs e)
    {
        // Module logic here
    }
}

• Enable failed request tracing in IIS
• Verify the module appears in IIS module list (run appcmd list modules)
• Check Windows Event Viewer for loading errors
• Test with a simple "Hello World" module to isolate the issue

Remember that module behavior can differ between:
- IIS Express vs Full IIS
- x86 vs x64 builds
- Different .NET Framework versions
Always test in an environment that matches production.


This is a common pain point when transitioning from VS development server to IIS hosting. The key difference lies in how IIS 7+ handles modules between Integrated and Classic pipeline modes. Your web.config snippet shows legacy system.web/httpModules configuration, which only works in Classic mode.

For IIS Integrated Pipeline (default in modern IIS), you must declare modules in system.webServer section:

<system.webServer>
    <modules>
        <add name="MyModule" 
            type="MySolution.Web.MyHttpModule, MySolution.Web" 
            preCondition="managedHandler" />
    </modules>
</system.webServer>

If you need to support both environments during development, use this hybrid approach:

<system.web>
    <httpModules>
        <clear />
        <add name="MyModule" type="MySolution.Web.MyHttpModule, MySolution.Web"/>
    </httpModules>
</system.web>
<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="false">
        <remove name="MyModule"/>
        <add name="MyModule" type="MySolution.Web.MyHttpModule, MySolution.Web"/>
    </modules>
</system.webServer>

When debugging module loading issues:

  1. Check IIS logs (%SystemDrive%\inetpub\logs\LogFiles)
  2. Use Failed Request Tracing
  3. Verify assembly is deployed to bin folder
  4. Check GAC for conflicting versions

For more control, register modules programmatically in Global.asax:

protected void Application_Start()
{
    DynamicModuleUtility.RegisterModule(typeof(MyHttpModule));
}