ASP.NET Core 仍然使用 OWIN 吗? [英] Does ASP.NET Core still use OWIN?

查看:64
本文介绍了ASP.NET Core 仍然使用 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.

这个库过时了吗?

推荐答案

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,其中包含一堆键,如 owin.RequestBodyowin.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 库(例如 OWINMicrosoft.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆