By shannon on July 08, 2010

We recently had a case on a new ASP.Net web application where we needed to add a value to the Handler Mapping in IIS. This was to enable the use of local SQL Server Reporting functionality in the MVC 2.0 web application.

When the mapping was originally configured, it was added with a typo. This was easy enough to fix and everything seemed to work well. Eventually the reporting stopped working, and after troubleshooting the issue, it was discovered that the Handler Mapping was once again set back to the version with the typo.

First thoughts were that there was something in the build/deployment process that was setting this, a script or something. After walking through the deployment process step by step, it was determined that just restarting IIS was resetting the Handler Mapping to the version with the typo in it.

This seemed really odd, and short of deleting the web application and starting from scratch, hoping that this issue would be resolved, I was looking for a less destructive fix.

It turned out to be fairly simple. With a couple adjustments to the web.config for the application, the issue has been fixed.

We had originally created a Handler Mapping entry similar to the following:

Path:
Reserved.ReportViewerWebControl.axd

Type:
Microsoft.Reporting.Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Name:
Reserved-ReportViewerWebControl-axd

What we wanted was actually:

Path:
Reserved.ReportViewerWebControl.axd

Type:
Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Name:
Reserved-ReportViewerWebControl-axd

To fix this issue we added the following 2 lines to the web.config:

<remove name="Reserved-ReportViewerWebControl-axd" />

and

<add name="Reserved-ReportViewerWebControl-axd" path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />

These lines went into the section shown below making the section look similar to the following:

<system.webServer>
	<handlers>
		<remove name="Reserved-ReportViewerWebControl-axd" />
		<remove name="WebServiceHandlerFactory-Integrated"/>
		<remove name="ScriptHandlerFactory"/>
		<remove name="ScriptHandlerFactoryAppServices"/>
		<remove name="ScriptResource"/>
		<remove name="MvcHttpHandler"/>
		<remove name="UrlRoutingHandler"/>
		<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
		<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
		<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
		<add name="MvcHttpHandler" preCondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
		<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
		<add name="Reserved-ReportViewerWebControl-axd" path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />
	</handlers>
</system.webServer>