5

My impression of one of the big benefits of Owin is that it makes it easy to run different web frameworks side-by-side without IIS's IHttpHandler. (This would be huge for distributing vertical functionality slices as nuget features.)

However every tutorial and article I find talks of things like self-host and a single framework. This is not what I'm interested in, I'm interested in running mvc, nancy, web api, maybe even webforms in the same application.

Am I wrong about OWIN enabling this? Say I want

  • Mvc to handle most requests
  • Webforms to handle requests which have a version=legacy header
  • Nancy to handle requests to /Nancy/...

How would I configure my Startup class to enable this?

George Mauer
  • 117,483
  • 131
  • 382
  • 612
  • In theory what you suggest should be possible, but in practice there are few standards that allow these pieces from different authors to work together. I am building OWIN.Framework NuGet that addresses this, but it's at a fairly early stage. – bikeman868 Mar 20 '17 at 04:56

1 Answers1

14

Although the use case sounds a bit absurd, you're absolutely right that OWIN enables this. You can compose your pipeline in all kinds of crazy ways.

Straight Pipeline

A typical "straight" pipeline would look something like this:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseWebApi(new MyHttpConfiguration());
        app.MapSignalR();
        app.UseNancy();
    }
}

This will work as follows (given you're hosting on http://localhost/)

  • WebAPI - http://localhost/api/* (default routing)
  • SignalR - http://localhost/signalr (default route)
  • Nancy - http://localhost/* (will handle everything else)

Branched Pipeline

You can also create branches in your pipeline:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseWebApi(new MyHttpConfiguration());

        app.Map("/newSite", site =>
        {
            site.MapSignalR();
            site.UseNancy();
        });
    }
}

This will work as follows (given you're hosting on http://localhost/)

  • WebAPI - http://localhost/api/* (default routing)
  • SignalR - http://localhost/newSite/signalr (default route)
  • Nancy - http://localhost/newSite/* (will handle everything else)
khellang
  • 17,550
  • 6
  • 64
  • 84
  • Ah thanks. My use case at the moment is just a simple playground project. The end goal is to be able to write the JasmineTest nuget package (of which I'm the maintainer) as an owin module rather than a controller distributed via content. – George Mauer Mar 06 '14 at 17:08
  • What nuget is `MapPath` in? I can't seem to find it. – George Mauer Mar 06 '14 at 18:48
  • There's `MapWhen` is that what you meant? The straight pipeline stuff didn't work but I was able to get it working with `MapWhen` – George Mauer Mar 06 '14 at 19:01
  • It looks like it's just `Map` now... http://msdn.microsoft.com/en-us/library/owin.mapextensions(v=vs.111).aspx – khellang Mar 06 '14 at 19:41
  • 1
    MapWhen is for your second sample, where you want to inspect headers etc. before determining if you want to go down that branch. – khellang Mar 06 '14 at 19:42
  • 2
    [Jabbr](https://github.com/jabbr/jabbr) is a great example. Check out [their startup class](https://github.com/JabbR/JabbR/blob/e40634b4e6594ce4ebd6aea0a6864b8f61b1ed02/JabbR/App_Start/Startup.cs). – jrsconfitto Mar 06 '14 at 20:05
  • Good link for code samples of all strategies => https://learn.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/katana-samples – ryanulit Jun 29 '17 at 15:05