Skip to content

How to User HttpHandler such as .ashx file with IIS7 Integrated Mode, Webfarm Environment

Updated: at 11:17 PM

Recently, we've moved our hosting for the Silicon Valley Code Camp to MOSSO, which is a hosted web farm.  In order to run modules and handlers, it seems it's necessary to run in IIS7's integrated mode.  Once this is set, other small issues creep up like for example you can no longer run HttpHandler's from the standard HttpHandler's section in your web.config file (see below)

<httpHandlers>
            <remove verb="*" path="*.asmx"/>
            <add verb="*" path="*.asmx" validate="false" ...
            <add verb="*" path="*_AppService.axd" validate="false" ...
            <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler,..
            <add type="PeterKellner.Utils.CaptchaTypeHandler" verb="GET" path="CaptchaType.ashx"/>
</httpHandlers>

 

In order to make this work, you have to do two things.  First, as MOSSO suggest on their web site http://help.mosso.com/article.php?id=260 you need to set a section in your <system.webServer> section called <staticContent>.  Second, you need to add to the the same handler you defined in the old section to the <handlers> section of the <system.webServer> section.  Make sure you add a name tag because that's required in this section, where as it's not required in the <HttpHandlers> section.

    <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <staticContent>
      <mimeMap fileExtension=".ashx" mimeType="text/html" />
    </staticContent>
    <modules  runAllManagedModulesForAllRequests="true"  >
            <remove name="ScriptModule"/>
            <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers....
      <add type="HealthMonitor.GeneralErrorModule,HealthMonitor" name="GeneralErrorModule"/>
    </modules>
        <handlers>
            <remove name="WebServiceHandlerFactory-Integrated"/>
            <remove name="ScriptHandlerFactory"/>
            <remove name="ScriptHandlerFactoryAppServices"/>
            <remove name="ScriptResource"/>
            <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System....
            <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"...
            <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" ...
      <add name="CapthaTypeHandler" type="PeterKellner.Utils.CaptchaTypeHandler" verb="GET" path="CaptchaType.ashx"/>
    </handlers>
    </system.webServer>
    <runtime>

Hope this saves you some time!