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

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!

About Peter Kellner

Peter is a software professional specializing in mobile and web technologies. He has also been a Microsoft MVP for the past 7 years. To read more about Peter Kellner and his experience click here. For information about how Peter Kellner might be able to help you with your project click here.

Follow me:


Comments

  1. Hello there, I discovered your web site by way of Google even as looking for a related subject, your website got here up, it seems good. I have bookmarked it in my google bookmarks.

  2. thanks a millions! Peter.

  3. Hi could you please attach whole text. starting from :

    Now it is unreadable.

    Thank you.

  4. Given these findings, the Court held that Ms. ,

  5. Binjie Zhao says:

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

  6. But it works with IE only :(

  7. 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.

Your Comments

*

Protected with IP Blacklist CloudIP Blacklist Cloud

Follow

Get every new post delivered to your Inbox

Join other followers: