Day 10 ASP.NET Core Middleware

Day 10 ASP.NET Core Middleware

Don't be evil——Google (Google座右铭)

The ASP.NET Core request pipeline consists of a sequence of request delegates, called one after the other.
ASP.NET Core框架的“请求流水线”机制是由一系列被顺序执行的请求代理组成的。

Each delegate can perform operations before and after the next delegate.
每一个代理可以在将请求传递给下一个代理之前、或者之后进行操作。

A delegate can also decide to not pass a request to the next delegate, which is called short-circuiting the request pipeline. Short-circuiting is often desirable because it avoids unnecessary work.
当前代理也可以决定不把请求传递给下一个代理,这种情况称为“将请求流水线短路”。“短路”常常是有价值的,因为这么做可以避免一些不必要的工作。

For example, the static file middleware can return a request for a static file and short-circuit the rest of the pipeline.
比如,静态文件的中间件可以直接将文件返回给相关的请求,并将余下的流水线短路掉。

Exception-handling delegates need to be called early in the pipeline, so they can catch exceptions that occur in later stages of the pipeline.
负责异常处理的代理需要在流水线的早期阶段就被调用,这样这类代理就可以捕捉之后发生在流水线各环节的异常了。

The simplest possible ASP.NET Core app sets up a single request delegate that handles all requests.
最简单的ASP.NET Core应用可能就只设置一个请求代理,来处理所有的请求。

This case doesn't include an actual request pipeline. Instead, a single anonymous function is called in response to every HTTP request.
(由于只有一个代理)这种情况就没有包含一个真正的“请求流水线”了。同一个匿名函数会负责响应所有的HTTP请求。

You can chain multiple request delegates together with app.Use. The next parameter represents the next delegate in the pipeline.
你可以调用app.Use方法,把多个请求代理串联起来。”next”这个参数,代表了流水线中的下一个代理。

Remember that you can short-circuit the pipeline by not calling the next parameter. You can typically perform actions both before and after the next delegate.
记住,如果你想将流水线短路掉,你就不要调用next这个参数.。通常,你可以在下一个代理之前以及之后进行操作。

本文选自:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-2.1&tabs=aspnetcore2x

生词 音标 释义
consist [kənˈsɪst] v. 由……组成
a sequence of 一系列
request delegate 请求代理
perform [pərˈfɔ:rm] v. 执行
operation [ˌɑ:pəˈreɪʃn] n. 操作
decide [dɪˈsaɪd] v. 决定
short-circuiting v. 使发生短路
desirable [dɪˈzaɪrəbəl] adj. 可取的
avoid [əˈvɔɪd] v. 避免
unnecessary [ʌnˈnesəseri] adj. 不必要的,多余的
static [ˈstætɪk] adj. 静态的
middleware [ˈmɪdlwer] n. 中间设备;中间件
exception-handling 异常处理
catch exception 捕捉异常
occur [əˈkɚ] v. 发生;出现
stage [stedʒ] n. 阶段
set up 建立,设立
handle [ˈhændl] v. 处理
anonymous [əˈnɑ:nɪməs] adj. 匿名的
function [ˈfʌŋkʃən] n. 函数
chain [tʃen] v. 串联
multiple [ˈmʌltəpəl] adj. 多个的
parameter [pəˈræmɪtɚ] n. 参数
represent [ˌrɛprɪˈzɛnt] v. 代表
typically [ˈtɪpɪklɪ] adv. 通常
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,273评论 19 139
  • 蚕食 黄外的草坛中, 有我埋的心愿瓶。 我记得很清楚, 坑,是用手刨的, 很浅, 一场雨,就能把它示众。 瓶子,是...
    肖弓阅读 213评论 0 0
  • 离开,使一切变得简单 离家的这天是正月十二,过去的习俗,没过正月十五都算是过年。我坐在飞速行驶的高铁上,看着外面飞...
    小韩寒阅读 273评论 0 0
  • 坝子是我国云贵高原上的局部平原的地方名称,主要分布于山间盆地、河谷沿岸和山麓地带。云南是大山的故乡,植物的王国,这...
    行摄滇西阅读 1,077评论 0 0
  • 前段时间看到别人分享自己的搞机生活,突发奇想把自己的搞机生活写出来,不求别人点赞也不是炫耀,因为下面出来的产品没有...
    行空阅读 1,766评论 11 19