ASP.NET Core中间件记录管道图和内置中间件

管道记录

下图显示了 ASP.NET Core MVC 和 Razor Pages 应用程序的完整请求处理管道

中间件组件在文件中添加的顺序Program.cs定义了请求时调用中间件组件的顺序以及响应的相反顺序。该顺序对于安全性、性能和功能至关重要。

内置中间件记录

|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| 内置中间件 |||||| |
| 原文 ||| 翻译 ||||
| Middleware | Description | Order | 中间件 | 描述 | 命令 | |
| Authentication | Provides authentication support. | Before HttpContext.User is needed. Terminal for OAuth callbacks. | 验证 | 提供身份验证支持。 | 之前HttpContext.User是需要的。OAuth 回调终端。 | |
| Authorization | Provides authorization support. | Immediately after the Authentication Middleware. | 授权 | 提供授权支持。 | 紧接着身份验证中间件。 | |
| Cookie Policy | Tracks consent from users for storing personal information and enforces minimum standards for cookie fields, such as secure and SameSite. | Before middleware that issues cookies. Examples: Authentication, Session, MVC (TempData). | Cookie 政策 | 跟踪用户对存储个人信息的同意并强制执行 cookie 字段的最低标准,例如secure和SameSite。 | 在发布 cookie 的中间件之前。示例:身份验证、会话、MVC(临时数据)。 | |
| CORS | Configures Cross-Origin Resource Sharing. | Before components that use CORS. UseCors currently must go before UseResponseCaching due to this bug. | 跨域资源共享 | 配置跨源资源共享。 | 在使用 CORS 的组件之前。由于这个错误,UseCors目前必须先走。UseResponseCaching | |
| DeveloperExceptionPage | Generates a page with error information that is intended for use only in the Development environment. | Before components that generate errors. The project templates automatically register this middleware as the first middleware in the pipeline when the environment is Development. | 开发者异常页面 | 生成一个包含错误信息的页面,该页面仅供在开发环境中使用。 | 在产生错误的组件之前。当环境为开发时,项目模板会自动将此中间件注册为管道中的第一个中间件。 | |
| Diagnostics | Several separate middlewares that provide a developer exception page, exception handling, status code pages, and the default web page for new apps. | Before components that generate errors. Terminal for exceptions or serving the default web page for new apps. | 诊断 | 几个独立的中间件,为新应用程序提供开发人员异常页面、异常处理、状态代码页面和默认网页。 | 在产生错误的组件之前。用于例外情况的终端或为新应用程序提供默认网页。 | |
| Forwarded Headers | Forwards proxied headers onto the current request. | Before components that consume the updated fields. Examples: scheme, host, client IP, method. | 转发标头 | 将代理标头转发到当前请求。 | 在使用更新字段的组件之前。示例:方案、主机、客户端 IP、方法。 | |
| Health Check | Checks the health of an ASP.NET Core app and its dependencies, such as checking database availability. | Terminal if a request matches a health check endpoint. | 健康检查 | 检查 ASP.NET Core 应用程序及其依赖项的运行状况,例如检查数据库可用性。 | 如果请求与健康检查端点匹配,则终端。 | |
| Header Propagation | Propagates HTTP headers from the incoming request to the outgoing HTTP Client requests. | | 标头传播 | 将 HTTP 标头从传入请求传播到传出 HTTP 客户端请求。 | | |
| HTTP Logging | Logs HTTP Requests and Responses. | At the beginning of the middleware pipeline. | HTTP 日志记录 | 记录 HTTP 请求和响应。 | 在中间件管道的开始处。 | |
| HTTP Method Override | Allows an incoming POST request to override the method. | Before components that consume the updated method. | HTTP 方法覆盖 | 允许传入的 POST 请求覆盖该方法。 | 在使用更新方法的组件之前。 | |
| HTTPS Redirection | Redirect all HTTP requests to HTTPS. | Before components that consume the URL. | HTTPS 重定向 | 将所有 HTTP 请求重定向到 HTTPS。 | 在使用 URL 的组件之前。 | |
| HTTP Strict Transport Security (HSTS) | Security enhancement middleware that adds a special response header. | Before responses are sent and after components that modify requests. Examples: Forwarded Headers, URL Rewriting. | HTTP 严格传输安全 (HSTS) | 添加特殊响应标头的安全增强中间件。 | 在发送响应之前和修改请求的组件之后。示例:转发标头、URL 重写。 | |
| MVC | Processes requests with MVC/Razor Pages. | Terminal if a request matches a route. | 多维控制器 | 使用 MVC/Razor 页面处理请求。 | 如果请求与路由匹配,则终端。 | |
| OWIN | Interop with OWIN-based apps, servers, and middleware. | Terminal if the OWIN Middleware fully processes the request. | 欧文 | 与基于 OWIN 的应用程序、服务器和中间件进行互操作。 | 如果 OWIN 中间件完全处理请求,则终端。 | |
| Output Caching | Provides support for caching responses based on configuration. | Before components that require caching. UseRouting must come before UseOutputCaching. UseCORS must come before UseOutputCaching. | 输出缓存 | 提供对基于配置的缓存响应的支持。 | 在需要缓存的组件之前。UseRouting必须先来UseOutputCaching。UseCORS必须先来UseOutputCaching。 | |
| Response Caching | Provides support for caching responses. This requires client participation to work. Use output caching for complete server control. | Before components that require caching. UseCORS must come before UseResponseCaching. Is typically not beneficial for UI apps such as Razor Pages because browsers generally set request headers that prevent caching. Output caching benefits UI apps. | 响应缓存 | 提供对缓存响应的支持。这需要客户的参与才能发挥作用。使用输出缓存来实现完整的服务器控制。 | 在需要缓存的组件之前。UseCORS必须先来UseResponseCaching。对于 Razor Pages 等 UI 应用程序通常没有好处,因为浏览器通常会设置阻止缓存的请求标头。输出缓存有利于 UI 应用程序。 | |
| Request Decompression | Provides support for decompressing requests. | Before components that read the request body. | 请求解压 | 提供对解压缩请求的支持。 | 在读取请求正文的组件之前。 | |
| Response Compression | Provides support for compressing responses. | Before components that require compression. | 响应压缩 | 提供对压缩响应的支持。 | 在需要压缩的组件之前。 | |
| Request Localization | Provides localization support. | Before localization sensitive components. Must appear after Routing Middleware when using RouteDataRequestCultureProvider. | 请求本地化 | 提供本地化支持。 | 敏感元件本地化之前。使用RouteDataRequestCultureProvider时必须出现在路由中间件之后。 | |
| Endpoint Routing | Defines and constrains request routes. | Terminal for matching routes. | 端点路由 | 定义和约束请求路由。 | 匹配路线的终端。 | |
| SPA | Handles all requests from this point in the middleware chain by returning the default page for the Single Page Application (SPA) | Late in the chain, so that other middleware for serving static files, MVC actions, etc., takes precedence. | 温泉 | 通过返回单页应用程序 (SPA) 的默认页面来处理中间件链中这一点的所有请求 | 在链的后期,以便其他用于提供静态文件、MVC 操作等的中间件优先。 | |
| Session | Provides support for managing user sessions. | Before components that require Session. | 会议 | 提供对管理用户会话的支持。 | 在需要 Session 的组件之前。 | |
| Static Files | Provides support for serving static files and directory browsing. | Terminal if a request matches a file. | 静态文件 | 提供对服务静态文件和目录浏览的支持。 | 如果请求与文件匹配则终端。 | |
| URL Rewrite | Provides support for rewriting URLs and redirecting requests. | Before components that consume the URL. | 网址重写 | 提供对重写 URL 和重定向请求的支持。 | 在使用 URL 的组件之前。 | |
| W3CLogging | Generates server access logs in the W3C Extended Log File Format. | At the beginning of the middleware pipeline. | W3C日志记录 | 以W3C 扩展日志文件格式生成服务器访问日志。 | 在中间件管道的开始处。 | |
| WebSockets | Enables the WebSockets protocol. | Before components that are required to accept WebSocket requests. | WebSockets | 启用 WebSocket 协议。 | 在接受 WebSocket 请求所需的组件之前。 | |

相关推荐
我叫啥都行36 分钟前
计算机基础知识复习9.7
运维·服务器·网络·笔记·后端
无名指的等待7121 小时前
SpringBoot中使用ElasticSearch
java·spring boot·后端
.生产的驴2 小时前
SpringBoot 消息队列RabbitMQ 消费者确认机制 失败重试机制
java·spring boot·分布式·后端·rabbitmq·java-rabbitmq
AskHarries2 小时前
Spring Boot利用dag加速Spring beans初始化
java·spring boot·后端
苹果酱05673 小时前
一文读懂SpringCLoud
java·开发语言·spring boot·后端·中间件
掐指一算乀缺钱3 小时前
SpringBoot 数据库表结构文档生成
java·数据库·spring boot·后端·spring
计算机学姐5 小时前
基于python+django+vue的影视推荐系统
开发语言·vue.js·后端·python·mysql·django·intellij-idea
JustinNeil6 小时前
简化Java对象转换:高效实现大对象的Entity、VO、DTO互转与代码优化
后端
青灯文案16 小时前
SpringBoot 项目统一 API 响应结果封装示例
java·spring boot·后端
微尘87 小时前
C语言存储类型 auto,register,static,extern
服务器·c语言·开发语言·c++·后端