Question

I have a self-hosting Owin HttpListener application using NancyFx.

I am wondering if it is possible to add to this project a WebApi Controller and make sure that a certain route is served only by this WebApi Controller.

It would be really nice to see an example of this working.

Was it helpful?

Solution

It is only possible if you if you use OWIN and HttpListener from the Katana Project. You can either host Nancy and WebApi on separate paths using the map middleware:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.Map("/nancy", branch => branch.UseNancy())
           .Map("/webapi", branch => branch.UseWebApi());
    }
}

Or you can configure Nancy to pass-through to subsequent middleware if, for example, Nancy is responding with a 404:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseNancy(opt => 
                     opt.PassThroughWhenStatusCodesAre(HttpStatusCode.NotFound)
           .UseWebApi();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top