一.Run方法

public static void Run(this IapplicationBuilder app,RequestDelegate hanler);是一个扩展方法

终端中间件:

app.Run(async(context)=>

{

await context.Response.WriteAsync("Hello World");

});

context是HttpContext的一个实例

终端中间件只能有一个,若是有多个,只会运行第一个终端中间件

2.调用下一个中间件

app.Use(async (context)=>

{

//配置响应内容的格式

context.Response.ContentType="text/plian;charset=utf-8";

logger.LogInformation("第一次");

await context.Reponse.WriteAsync("你好");

//next()是一个Fun<Task>next的委托,用来调用下一个中间件

await next();

logger.LogInfomation("响应");

});

app.Run(async(context)=>

{

logger.LogInfomation("传入请求你");

await context.Response.WriteAsync("你好呀");

});

总结:请求处理的管道:先从use中间件===>中间件====>use中间件  或者 传入请求==>传入请求==>处理并响应请求==>传出响应请求==>处理响应请求。所有的请求处理都会在每个中间件调用next()方法之前触发。依次穿过管道,到了终端中间件时会发生逆转传递请求。

 

 

配置Asp.NET Core请求处理管道

 

 

相关文章:

  • 2021-10-28
  • 2022-01-14
  • 2021-09-03
  • 2023-02-15
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-16
  • 2022-02-05
  • 2021-06-15
  • 2021-07-17
  • 2021-09-09
相关资源
相似解决方案