ASP.NET Core middleware or OWIN middleware?

不羁的心 提交于 2019-12-03 11:07:07

问题


As I understand it, ASP.NET Core has support for OWIN middleware (via app.UseOwin()) in addition to its own native middleware.

What is the difference between ASP.NET Core middleware and OWIN middleware?

When designing a new middleware, how do I know if I should design it as a ASP.NET Core middleware or a OWIN middleware?


回答1:


Your question made me curious and I would like to share, what I have learned so far.

Katana is the implementation of the OWIN spec. After version 3.0 of Katana this technology has been fully integration in the web stack we know as ASP.NET Core today.

While this transition much has stayed similar to the OWIN specifications. Although some changes have been made. In order to use existing OWIN middleware in ASP.NET Core the supports OWIN by an optional feature ("app.UseOwin()").

If you want to target with your middleware ASP.NET apps and ASP.NET core apps, then I would use OWIN middleware. If you want to give ASP.NET Core developers a first class citizen experience, then a ASP.NET Core middleware would be recognized as more "fitting".

Some information about the relationship between ASP.NET Core middleware and OWIN middleware can be found here:

  • Katana, ASP.NET 5, and bridging the gap
  • Katana Project
  • https://docs.asp.net/en/latest/fundamentals/owin.html



回答2:


I have come to understand it as this; ASP.NET Core middleware is on a higher level than OWIN middleware which is on a lower level.

ASP.NET Core middleware has the advantage that it is much easier to develop a middleware in as you get passed in the HttpContext which you can use. The disadvantage is that the middleware you develop depends on ASP.NET Core.

OWIN is on a lower level and you get a OWIN environment which is a IDictionary<string, object>. The advantage is that is it not tied to ASP.NET hence can run on any OWIN server (such as Nowin). The disadvantage is that it takes more effort to code since you have to build your own context from the OWIN environment or use the OWIN environment dictionary directly and keep track of all OWIN keys and objects.

Edit: You don't have to keep track of OWIN keys yourself, you can use the OwinEnvironment class to get a strongly typed environment.

var environment = new OwinEnvironment(HttpContext);
var features = new OwinFeatureCollection(environment);


来源:https://stackoverflow.com/questions/39429122/asp-net-core-middleware-or-owin-middleware

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!