Search code examples
c#handlerashxwebapi

Call handler without specifying ashx file on URL?


I have a handler called HandlerGeoserver

If I call localhost:55000/HandlerGeoserver.ashx on runtime everything works fine. I need to remove the HandlerGeoserver.ashx text from the URL, and make the request to be handled by the handler.

localhost:55000/ fires the HandlerGeoserver.ashx

Is this possible?

  • If not, an option I considered is to set via web.config to route / routes to handlerGeoserver.ashx, but don't know if this is possible.

  • Another option I considered was to combine the handler with webapi, so that when calling a route from the api (localhost:55000/), the controller redirects the call to the handler. Do you think this could be a good approximation?


Solution

  • Finally solved creating a rewrite rule on my web.config as following:

    <rewrite>
       <rules>
          <rule>
             <match url="/" />
             <action type="Rewrite" url="HandlerGeoserver.ashx" />
          </rule>
       </rules>
    </rewrite>
    

    It is the simplest and most effective solution I found.