Is it possible to serve ashx / axd in a console application?

Hey ServiceStack,

I was curious if it was possible to serve up ashx or axd files in ServiceStack. I have not done much research into this so I figured I would ask first, before investing any time into it.

Thanks,
Ryan

It’s not in ServiceStack you’d be serving .ashx / .axd from, it’s in ASP.NET.

ServiceStack is itself just a ASP.NET HttpHandler but if it’s registered at / root path it handles all requests. To allow ASP.NET to serve other extensions you’d need to host ServiceStack on a custom path in order to allow it to fall through and execute the best matching ASP.NET Handler.

Otherwise you could potentially just register other ASP.NET Handlers before ServiceStack so it has the higher priority, e.g:

<system.webServer>
  <validation validateIntegratedModeConfiguration="false" />
  <handlers>
    <!-- Register other handlers -->
    <add path="*" name="ServiceStack.Factory" preCondition="integratedMode" 
         type="ServiceStack.HttpHandlerFactory, ServiceStack" 
         verb="*" resourceType="Unspecified" allowPathInfo="true" />
  </handlers>
</system.webServer>

Another option is to register a RawHttpHandler which allows you to return an ASP.NET IHttpHandler which will completely by-pass ServiceStack and execute your IHttpHandler instead.

E.g. this is what Server Events uses to register its handlers:

appHost.RawHttpHandlers.Add(httpReq =>
    httpReq.PathInfo.EndsWith(StreamPath)
        ? (IHttpHandler)new ServerEventsHandler()
        : httpReq.PathInfo.EndsWith(HeartbeatPath)
            ? new ServerEventsHeartbeatHandler()
            : null);