Search code examples
asp.nethttphandlerashx

Classic to integrated mode, http handlers not running


I'm migrating an old application from classic mode to integrated mode, and the previously registered http handlers no longer work. I've placed the handlers section under system.webServer where they're supposed to go, but no dice:

<system.webServer>
  <handlers>
    ...
    <add name="zip.ashx_*" path="zip.ashx" verb="*" type="ZipDownloadHandler, Assembly" preCondition="integratedMode,runtimeVersionv2.0" resourceType="Unspecified" />
    <add name="file.ashx_*" path="file.ashx" verb="*" type="FileDownloadHandler, Assembly" preCondition="integratedMode,runtimeVersionv2.0" resourceType="Unspecified" />
    <add name="stream.ashx_*" path="stream.ashx" verb="GET" type="StreamDownloadHandler, Assembly" preCondition="integratedMode,runtimeVersionv2.0" resourceType="Unspecified" />
  </handlers>
...
</system.webServer>

But they always return 404. The config dump from

appcmd list config "Default Web Site/MyApp" -section:system.webServer/handlers

displays the handlers correctly:

<system.webServer>
  <handlers accessPolicy="Read, Script">
    ...
    <add name="zip.ashx_*" path="zip.ashx" verb="*" type="ZipDownloadHandler, Assembly" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />
    <add name="file.ashx_*" path="file.ashx" verb="*" type="FileDownloadHandler, Assembly" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />
    <add name="stream.ashx_*" path="stream.ashx" verb="GET" type="StreamDownloadHandler, Assembly" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />
   ...

If I switch from stream.ashx to registering the handler path as stream.foo, I still get a 404, but the error page is different. For stream.ashx, it looks like this, and for stream.foo it looks like this.

Perhaps stream.ashx is actually triggering the *.ashx handler which then looks for a file named stream.ashx, but can't find one. I really don't know what's going on with the other handler though, because my config looks correct. Any suggestions would be appreciated.


Solution

  • I never did get this to work, so I simply replaced the module registration in web.config with a route handler:

    RouteTable.Routes.Add("stream", new Route("stream", new RouteHandler(new StreamDownloadHandler())));
    RouteTable.Routes.Add("file", new Route("file", new RouteHandler(new FileDownloadHandler())));
    RouteTable.Routes.Add("zip", new Route("zip", new RouteHandler(new ZipDownloadHandler())));