Search code examples
c#asp.netasp.net-web-apihttphandler

Route ashx path to ApiController


I have a legacy application where an ashx path used to go to an HttpHandler but I would like it to go to an ApiController without changing the path.

So my.application.com/auth/gettoken.ashx used to go to an "old-school" ashx.cs file, but now I want it to go to a regular WebAPI controller.

I've tried removing the handler and adding an ApiController with the correct route. This works locally, but not in production. I assume because my local IIS Express is configured differently than the production IIS.

Can I achieve this? I would be okay with disabling ashx handlers altogether. I've tried this in my web.config, but it didn't work:

<remove name="SimpleHandler"/>

I've looked into a redirect, but I'm doing a POST to this URL, so a redirect won't seem to work either.

So, can I, in any way, have a call to a path with an .ashx extension be routed to a regulare WebAPI ApiController?


Solution

  • I've currently reintroduced the ashx file, as I didn't find any other solution. If someone ever does, I'd happily mark that as the accepted answer (and change my code).