How to User HttpHandler such as .ashx file with IIS7 Integrated Mode, Webfarm Environment
Saturday 6 September 2008 @ 10:20 am


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!





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

  1. Mark Says:

    Good find!

    Our ambigrams are hosted with Mosso as well, and are all generated through customer HTTPHandlers.

    However, we don’t have the staticcontent element in our web.config. It also seems to work just fine to set the contenttype in the handler. Like this:

    app.response.contenttype=”text/html”

    We have both text and image content type handlers, and this line of code works for both. However, if we leave that out, we also have big issues.

    Anyway, just through I would let you know about another alternative.

  2. Andrei Says:

    But it works with IE only :(

  3. Binjie Zhao Says:

    Very helpful, saved my day! Thanks a lot for sharing.

  4. Daddy100 Says:

    Given these findings, the Court held that Ms. ,

  5. klaky Says:

    Hi could you please attach whole text. starting from :

    Now it is unreadable.

    Thank you.

Leave a Reply