美文网首页
Day 10 ASP.NET Core Middleware

Day 10 ASP.NET Core Middleware

作者: mocobk | 来源:发表于2018-07-20 12:25 被阅读0次

    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. 通常

    相关文章

      网友评论

          本文标题:Day 10 ASP.NET Core Middleware

          本文链接:https://www.haomeiwen.com/subject/lpifmftx.html