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.

有帮助吗?

解决方案

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();
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top