gpt4 book ai didi

asp.net - 是什么让某些东西成为 ASP.NET Core 中的请求功能?

转载 作者:行者123 更新时间:2023-12-04 15:09:27 31 4
gpt4 key购买 nike

ASP.NET Core 中有一点我相信我还没有完全理解,那就是请求功能的想法。如 the docs 中所述:

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.



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

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

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

最佳答案

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 行为的方法,如缓冲、发送文件、身份验证、websockets。

中间件还可以添加特定于该中间件的功能,您可以看到这样的示例:
  • 异常处理程序中间件处理通过请求功能发生的异常 - https://github.com/aspnet/Diagnostics/blob/dev/src/Microsoft.AspNetCore.Diagnostics.Abstractions/IExceptionHandlerFeature.cs .
  • 路由中间件通过请求特性将路由数据添加到当前的 http 上下文 - https://github.com/aspnet/Routing/blob/dev/src/Microsoft.AspNetCore.Routing.Abstractions/IRoutingFeature.cs

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

    关于asp.net - 是什么让某些东西成为 ASP.NET Core 中的请求功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34994344/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com