ASP.NET Core 注册中间件_使用IApplicationBuilder注册中间件
一、ASP.NET Core 注册中间件_使用IApplicationBuilder注册中间件
Use()
app.Use(async (context, next) => { await context.Response.WriteAsync("hello world"); await next.Invoke(); }); app.Use((next) => { return async (context) => { await context.Response.WriteAsync("hello world2"); await next(context); }; });
绑定上传:
//绑定WebSocket处理,接收成功后,生成缩略图 UploadHandle.ServerInfo.SitePath = env.WebRootPath; //使用wwwroot作为根目录 app.Map("/upload/common", (con) => { con.UseWebSockets();//启用webscoket con.Use(async (ctx, next) => { Receiver _receive = new Receiver(ctx, "upload/images"); _receive.OnSuccess += (data) => { }; _receive.OnError += (ex) => { int i = 10; }; await _receive.DoWork(); await next.Invoke(); }); });
更多:
Asp.Net Core 6获取IHttpContextAccessor方法