ASP.NET Core是否仍使用OWIN? [英] Does ASP.NET Core still use OWIN?
问题描述
在使用C#构建较旧的MVC项目时,我注意到,有很多对OWIN库的引用.但是,在VS2015 SP3中创建.NET Core Web应用程序时,似乎没有对其的引用.
I noticed when using C# to build an older MVC project, that there is a lot of references to an OWIN library. But when creating a .NET Core web application in VS2015 SP3, seems there's no reference to it.
这个图书馆被淘汰了吗?
Is this library obsoleted?
推荐答案
OWIN不是库,它是规范 .在文档中,
OWIN is not a library, it's a specification. From the docs,
OWIN定义了.NET Web服务器和Web应用程序之间的标准接口.
OWIN defines a standard interface between .NET web servers and web applications.
OWIN的大想法"是,如果每个人都可以就使用的通用接口达成一致,则可以将应用程序与运行它们的服务器脱钩.实际上,兼容OWIN的服务器可以运行任何兼容OWIN的应用程序.这是对我们过去紧密耦合的一种改进(应用程序只能在IIS上运行,仅此而已).
The "big idea" of OWIN is that you can decouple applications from the servers they run on, if everyone can agree on a common interface to use. In practice, an OWIN-compatible server can run any OWIN-compatible application. This is an improvement over the tight coupling we've had in the past (applications can only run on IIS, and that's it).
许多OWIN规范专用于描述各种属性的名称.兼容OWIN的服务器将传入的请求转换为Dictionary<string, object>
,其中包含一堆密钥,例如owin.RequestBody
和owin.ResponseBody
.如果将请求传递给的应用程序或中间件知道如何读取这些密钥,则它可以处理该请求.就是这样!
A lot of the OWIN spec is dedicated to describing the names of various properties. An OWIN-compatible server transforms incoming requests into a Dictionary<string, object>
that contains a bunch of keys like owin.RequestBody
and owin.ResponseBody
. If the application or middleware that the request is passed to knows how to read those keys, it can process the request. That's it!
有 个OWIN库(例如 OWIN 和 Microsoft.Owin ),这是造成混乱的常见原因.这些库只是OWIN接口的类型安全的实现,还是使与OWIN兼容的组件更容易交互的帮助程序.
There are OWIN libraries (like OWIN and Microsoft.Owin), which is a common source of confusion. These libraries are just type-safe implementations of the OWIN interface, or helpers that make it easier to interact with components that are OWIN-compatible.
正如@Murray和@Tseng指出的那样,ASP.NET Core不是基于OWIN构建的,而是与OWIN兼容的.或者,运行ASP.NET Core的服务器(Kestrel,WebListener,IIS)是OWIN兼容的. ASP.NET Core是对低级请求("OWIN级别")的进一步抽象,使构建控制器和服务器呈现的页面等内容变得容易.
As @Murray and @Tseng pointed out, ASP.NET Core is not built on OWIN, but it is OWIN-compatible. Or, rather, the servers that ASP.NET Core run on (Kestrel, WebListener, IIS) are OWIN-compatible. ASP.NET Core is a further abstraction over low-level requests (the "OWIN level") and makes it easy to build things like controllers and server-rendered pages.
由于ASP.NET Core 与OWIN兼容,因此很容易插入任何与OWIN兼容的中间件. Microsoft.AspNetCore.Owin
包公开了UseOwin
方法:
Since ASP.NET Core is OWIN-compatible, it's easy to plug in any OWIN-compatible middleware. The Microsoft.AspNetCore.Owin
package exposes a UseOwin
method:
app.UseOwin(pipeline =>
{
pipeline(next => OwinHello);
// where OwinHello is a compatible middleware function
});
请参阅文档,以获取将OWIN中间件添加到的更多示例. ASP.NET Core管道.
See the documentation for more examples of adding OWIN middleware to the ASP.NET Core pipeline.
这篇关于ASP.NET Core是否仍使用OWIN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!