Resolving Missing ASP.NET 4.0 Handler Mappings in IIS7: AJAX Calls Fail While Pages Load


2 views

When working with ASP.NET 4.0 applications on IIS7/Windows Server 2008 R2, you might encounter a peculiar situation where:

  • Regular ASPX pages load correctly
  • All AJAX calls (including UpdatePanel, PageMethods, or Web Services) fail
  • Handler mappings for .NET 4.0 extensions (.aspx, .ashx, .axd, etc.) are missing in IIS

The absence of these handler mappings prevents IIS from properly routing requests to the ASP.NET 4.0 runtime. While basic pages might work due to static file handling, dynamic processing (like AJAX) requires these mappings.

The standard aspnet_regiis -ir command sometimes fails to properly register handlers in IIS7+. Here's the complete solution sequence:

1. Open elevated command prompt (Run as Administrator)
2. Navigate to .NET 4.0 Framework directory:
   cd %windir%\Microsoft.NET\Framework64\v4.0.30319
3. Execute these commands in order:
   aspnet_regiis -u
   aspnet_regiis -i
   iisreset

After running these commands, check IIS Manager:

  1. Open IIS Manager
  2. Select server node (not individual sites)
  3. Open "Handler Mappings" feature
  4. Look for entries prefixed with "ASP.NET v4.0" like:
    • ASP.NET v4.0.30319 - *.aspx
    • ASP.NET v4.0.30319 - *.ashx
    • ASP.NET v4.0.30319 - *.axd

If the above fails, you can manually add handler mappings by creating a PowerShell script:

# PowerShell script to add ASP.NET 4.0 handlers
Import-Module WebAdministration

$handlers = @{
    "ASP.NET v4.0.30319 - *.aspx" = "*.aspx"
    "ASP.NET v4.0.30319 - *.ashx" = "*.ashx"
    "ASP.NET v4.0.30319 - *.axd" = "*.axd"
    "ASP.NET v4.0.30319 - *.cshtm" = "*.cshtm"
    "ASP.NET v4.0.30319 - *.soap" = "*.soap"
}

foreach ($handler in $handlers.GetEnumerator()) {
    Add-WebHandler -Name $handler.Key -Path $handler.Value -Verb "*" -Type "System.Web.UI.PageHandlerFactory" -Modules "ManagedPipelineHandler" -Precondition "integratedMode" -Force
}

While you mentioned wanting to avoid web.config changes, here's what a minimal handler registration might look like as a temporary solution:

<system.webServer>
  <handlers>
    <add name="ASP.NET v4.0 PageHandler" path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" preCondition="integratedMode,runtimeVersionv4.0" />
    <add name="ASP.NET v4.0 ServiceHandler" path="*.asmx" verb="*" type="System.Web.Services.Protocols.WebServiceHandlerFactory" preCondition="integratedMode,runtimeVersionv4.0" />
  </handlers>
</system.webServer>

Before considering framework reinstallation:

  • Verify .NET 4.0 is actually installed (check %windir%\Microsoft.NET\Framework64\v4.0.30319)
  • Ensure IIS "ISAPI and CGI Restrictions" has .NET v4.0 enabled
  • Check Application Pool is configured for .NET 4.0 and Integrated Pipeline mode

During a recent server deployment, I encountered a bizarre situation where a perfectly functioning ASP.NET 4.0 application suddenly stopped processing AJAX requests. The web pages loaded normally, but all client-side AJAX calls returned 404 errors. Upon investigation, I discovered the IIS7 handler mappings for .NET 4.0 were completely missing - no entries for .aspx, .ashx, or other crucial extensions.

Comparing the problematic server with a working one revealed striking differences:


Working Server:
- StaticFile (Default)
- ASP.NET-4.0.30319.0 (for *.aspx)
- ASP.NET-4.0.30319.0 (for *.ashx)
- ExtensionlessUrlHandler-4.0

Broken Server:
- StaticFile (Default)
- ExtensionlessUrlHandler-4.0

The missing handlers particularly affect AJAX functionality because:

  • WebMethods in ASP.NET pages rely on .aspx handler
  • ASMX web services require .soap handler
  • Custom HTTP handlers (.ashx) won't process requests

Before finding the real solution, I tried several approaches:


1. Running aspnet_regiis -ir (no effect)
2. Repairing .NET 4.0 installation
3. Manually adding handlers in IIS
4. Recycling application pools

The solution involved two critical steps:


1. Open "Turn Windows Features on or off"
2. Navigate to: 
   - Internet Information Services
   - World Wide Web Services
   - Application Development Features
3. Ensure "ASP.NET 4.5" is checked (this includes 4.0 handlers)
4. Click OK and wait for installation

For those who prefer command-line approach:


dism /online /enable-feature /featurename:IIS-ASPNET45

After applying the fix, you should see:


Handler Mappings now show:
- PageHandlerFactory-4.0 (for *.aspx)
- SimpleHandlerFactory-4.0 (for *.ashx)
- WebServiceHandlerFactory-4.0 (for *.soap)
- etc.

If the above doesn't work, you can manually add handlers in web.config:


<system.webServer>
  <handlers>
    <add name="PageHandlerFactory-4.0" 
         path="*.aspx" 
         verb="*" 
         type="System.Web.UI.PageHandlerFactory" 
         preCondition="integratedMode,runtimeVersionv4.0"/>
    <add name="SimpleHandlerFactory-4.0" 
         path="*.ashx" 
         verb="*" 
         type="System.Web.UI.SimpleHandlerFactory" 
         preCondition="integratedMode,runtimeVersionv4.0"/>
  </handlers>
</system.webServer>

To avoid this issue in future deployments:

  • Always verify IIS features during server provisioning
  • Include these checks in your deployment checklist
  • Consider using Web Deploy to ensure consistent configurations