ASP.NET Core 註冊中介軟體_使用IApplicationBuilder註冊中介軟體
阿新 • • 發佈:2022-03-09
一、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方法