Task 27: Middleware introduction pipe

Task 27: Middleware introduction pipe

 

 

HttpContext

The figure registered three middleware, all httpContext HttpContext will perform on three pipelines would write something in Reponse inside. Everything will be superimposed to the HttpContext Reponse them, I finally returned to our Reponse in.

 

 

 

 

 

 

Receiving a RequestDelegate, returning a RequestDelegate

app.Use(next=>{
                return (context)=>{
                    context.Response.WriteAsync("2: in the middle of start...");
                    return next(context);
                };
            });
Receiving RequestDelegate

 

Use app.use registration middleware (middleware)

 

dotnet run run the program

If we do not perform the second step, then the next method. The results of the output

Back middleWare will not be executed.

 

app.Map method: to provide a mechanism for our route, and later talked about the routing of the middleware is relevant

For instance, we reached / Task he will provide us with an Action

He received a ApplicationBuilder

Map EDITORIAL We must, otherwise the pipeline was cut off

http: // localhost: 5000 / task we have only entered in the browser / task to see the results of our middleware output.

这种方式是后面我们用来构建路由的基础。

这就是我们讲的APplicationBuilder的用到的三个方法 use、run、map注册中间件的三个方法

 



如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。

任务27:Middleware管道介绍

 

 

HttpContext

图中注册了三个中间件,所有httpContext就会在这三个管道上都执行HttpContext,会在Reponse里面写一些东西。所有东西会叠加到HttpContext的Reponse当中,最后返回给我我们的Reponse中。

 

 

 

 

 

 

接收一个RequestDelegate,再返回一个RequestDelegate

app.Use(next=>{
                return (context)=>{
                    context.Response.WriteAsync("2: in the middle of start...");
                    return next(context);
                };
            });
接收RequestDelegate

 

使用app.use注册middleware(中间件)

 

dotnet run 运行程序

如果我们第二步不执行next方法的话。那么输出的结果

后面的middleWare就不会执行了。

 

app.Map方法:提供给我们一个路由的机制,这个和后面讲到的路由的middleware是相关的

比如说我们传到/Task 他会提供给我们一个Action

接收了一个ApplicationBuilder

Map我们要写在前面,否则管道就被截断了

http://localhost:5000/task 我们只有在浏览器中输入/task才能看到我们的中间件输出的结果。

这种方式是后面我们用来构建路由的基础。

这就是我们讲的APplicationBuilder的用到的三个方法 use、run、map注册中间件的三个方法

 



如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。

Guess you like

Origin www.cnblogs.com/owenzh/p/11306985.html