.net core中间件
2020-08-24 22:42 石吴玉 阅读(349) 评论(0) 编辑 收藏 举报.net core处理流程是一个管道,中间件位于管道内部,有序排队,请求进来时依次通过中间件,且决定是否进入下一中间件,请求返回时,也依次倒叙离开中间件。
指向下一个中间件:return next();
public void Configure(IApplicationBuilder app) { app.Use((context, next) => { var cultureQuery = context.Request.Query["culture"]; if (!string.IsNullOrWhiteSpace(cultureQuery)) { var culture = new CultureInfo(cultureQuery); CultureInfo.CurrentCulture = culture; CultureInfo.CurrentUICulture = culture; } // Call the next delegate/middleware in the pipeline return next(); }); app.Run(async (context) => { await context.Response.WriteAsync( $"Hello {CultureInfo.CurrentCulture.DisplayName}"); }); }