当先锋百科网

首页 1 2 3 4 5 6 7

管道记录

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

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

内置中间件记录

内置中间件
原文翻译
MiddlewareDescriptionOrder中间件描述命令
AuthenticationProvides authentication support.Before HttpContext.User is needed. Terminal for OAuth callbacks.验证提供身份验证支持。之前HttpContext.User是需要的。OAuth 回调终端。
AuthorizationProvides authorization support.Immediately after the Authentication Middleware.授权提供授权支持。紧接着身份验证中间件。
Cookie PolicyTracks 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 字段的最低标准,例如secureSameSite在发布 cookie 的中间件之前。示例:身份验证、会话、MVC(临时数据)。
CORSConfigures Cross-Origin Resource Sharing.Before components that use CORS. UseCors currently must go before UseResponseCaching due to this bug.跨域资源共享配置跨源资源共享。在使用 CORS 的组件之前。由于这个错误,UseCors目前必须先走。UseResponseCaching
DeveloperExceptionPageGenerates 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.开发者异常页面生成一个包含错误信息的页面,该页面仅供在开发环境中使用。在产生错误的组件之前。当环境为开发时,项目模板会自动将此中间件注册为管道中的第一个中间件。
DiagnosticsSeveral 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 HeadersForwards proxied headers onto the current request.Before components that consume the updated fields. Examples: scheme, host, client IP, method.转发标头将代理标头转发到当前请求。在使用更新字段的组件之前。示例:方案、主机、客户端 IP、方法。
Health CheckChecks 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 PropagationPropagates HTTP headers from the incoming request to the outgoing HTTP Client requests.标头传播将 HTTP 标头从传入请求传播到传出 HTTP 客户端请求。
HTTP LoggingLogs HTTP Requests and Responses.At the beginning of the middleware pipeline.HTTP 日志记录记录 HTTP 请求和响应。在中间件管道的开始处。
HTTP Method OverrideAllows an incoming POST request to override the method.Before components that consume the updated method.HTTP 方法覆盖允许传入的 POST 请求覆盖该方法。在使用更新方法的组件之前。
HTTPS RedirectionRedirect 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 重写。
MVCProcesses requests with MVC/Razor Pages.Terminal if a request matches a route.多维控制器使用 MVC/Razor 页面处理请求。如果请求与路由匹配,则终端。
OWINInterop with OWIN-based apps, servers, and middleware.Terminal if the OWIN Middleware fully processes the request.欧文与基于 OWIN 的应用程序、服务器和中间件进行互操作。如果 OWIN 中间件完全处理请求,则终端。
Output CachingProvides support for caching responses based on configuration.Before components that require caching. UseRouting must come before UseOutputCachingUseCORS must come before UseOutputCaching.输出缓存提供对基于配置的缓存响应的支持。在需要缓存的组件之前。UseRouting必须先来UseOutputCachingUseCORS必须先来UseOutputCaching
Response CachingProvides 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 DecompressionProvides support for decompressing requests.Before components that read the request body.请求解压提供对解压缩请求的支持。在读取请求正文的组件之前。
Response CompressionProvides support for compressing responses.Before components that require compression.响应压缩提供对压缩响应的支持。在需要压缩的组件之前。
Request LocalizationProvides localization support.Before localization sensitive components. Must appear after Routing Middleware when using RouteDataRequestCultureProvider.请求本地化提供本地化支持。敏感元件本地化之前。使用RouteDataRequestCultureProvider时必须出现在路由中间件之后。
Endpoint RoutingDefines and constrains request routes.Terminal for matching routes.端点路由定义和约束请求路由。匹配路线的终端。
SPAHandles 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 操作等的中间件优先。
SessionProvides support for managing user sessions.Before components that require Session.会议提供对管理用户会话的支持。在需要 Session 的组件之前。
Static FilesProvides support for serving static files and directory browsing.Terminal if a request matches a file.静态文件提供对服务静态文件和目录浏览的支持。如果请求与文件匹配则终端。
URL RewriteProvides support for rewriting URLs and redirecting requests.Before components that consume the URL.网址重写提供对重写 URL 和重定向请求的支持。在使用 URL 的组件之前。
W3CLoggingGenerates server access logs in the W3C Extended Log File Format.At the beginning of the middleware pipeline.W3C日志记录以W3C 扩展日志文件格式生成服务器访问日志。在中间件管道的开始处。
WebSocketsEnables the WebSockets protocol.Before components that are required to accept WebSocket requests.WebSockets启用 WebSocket 协议。在接受 WebSocket 请求所需的组件之前。