1. 程式人生 > 其它 >ASP.NET Core 註冊中介軟體_使用IApplicationBuilder註冊中介軟體

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方法

Asp.Net Core Mvc下載處理__Asp.Net Core Mvc檔案下載

Asp.Net Core 跨域處理_Ajax 跨域處理整理