要配置多个中间件,请使用Use()
扩展方法。与Run()
方法类似,不同之处在于它包括用于调用序列中的下一个中间件的下一个参数
public void Configure(IApplicationBuilder app, IHostingEnvironment env){
app.Use(async (context, next) =>{
await context.Response.WriteAsync("1st MW!");
await next();
});
app.Run(async (context) =>{
await context.Response.WriteAsync("2nd MW");
});
}