是什么使某些东西成为ASP.NET Core中的请求功能? [英] What makes something be a request feature in ASP.NET Core?

查看:72
本文介绍了是什么使某些东西成为ASP.NET Core中的请求功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信我还没有完全理解ASP.NET Core中的一点,那就是请求功能的概念。如文档中所述:

There's one point in ASP.NET Core that I believe I didn't fully understand yet and that is the idea of request features. As explained in the docs:


功能接口定义了给定请求可能支持的特定HTTP功能。服务器定义功能的集合以及该服务器支持的初始功能集,但是可以使用中间件来增强这些功能。

Feature interfaces define specific HTTP features that a given request may support. Servers define collections of features, and the initial set of features supported by that server, but middleware can be used to enhance these features.

我对此的初步理解是,请求功能是服务器应公开的所有东西,可以在应用程序管道上使用。也就是说,服务器应该执行的行为就像发送文件一样。

My initial understanding about this was that request features are all things a server should expose to be used on the application pipeline. That is, behaviors that a server should perform like sending a file.

另一方面,有身份验证请求功能。现在,我不确定身份验证是否属于此类。应用程序似乎不应该调用某些服务器行为,而应该关注应用程序本身。

On the other hand, there's, for example, the authentication request feature. Now, I'm not sure authentication falls into this category. It doesn't seem like some server behavior that the application should call, but rather, a concern of the application itself.

这让我想知道什么真正使某事成为请求功能。那么,是什么使某些东西成为ASP.NET Core中的请求功能呢?我最初的理解错了吗?

This makes me wonder what really makes something be a request feature. So, what makes something be a request feature in ASP.NET Core? Is my initial understanding wrong? What is behind the decision of making something a request feature?

推荐答案


我对此的最初理解是请求功能是服务器应公开在应用程序管道上使用的所有内容。也就是说,服务器应该执行的行为就像发送文件一样。

My initial understanding about this was that request features are all things a server should expose to be used on the application pipeline. That is, behaviors that a server should perform like sending a file.

这是http功能的一种用法。这也是一种增强或减轻HttpContext行为的方式,例如缓冲,发送文件,身份验证,WebSocket。

That's one use of http features. It's also a way to augment or light up behaviors on the HttpContext, like buffering, send file, authentication, websockets.

中间件还可以添加特定于该中间件的功能,您可以看到以下示例:

Middleware can also add features specific to that middleware, you can see examples of this:

  • The exception handler middleware flows the exception that occurred via a request feature - https://github.com/aspnet/Diagnostics/blob/dev/src/Microsoft.AspNetCore.Diagnostics.Abstractions/IExceptionHandlerFeature.cs.
  • The routing middleware adds route data to the current http context via a request feature - https://github.com/aspnet/Routing/blob/dev/src/Microsoft.AspNetCore.Routing.Abstractions/IRoutingFeature.cs

通常,这是一种将每个请求行为和状态从服务器通过中间件传递到应用程序的方式。

Generally it's a way to flow per request behavior and state from the server, through middleware, to the application.

这篇关于是什么使某些东西成为ASP.NET Core中的请求功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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