Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

.net - Run different frameworks side-by-side with OWIN

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...