• asp.net core 3.1 中Synchronous operations are disallowed. Call FlushAsync or set AllowSynchronousIO to true instead


         在进行 Asp.NetCore.MVC  文件上传时,后台无法正常读取文件流保存,出现:Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.

        

       查找资料,发现需要添加允许条件,才可以; 感谢:https://www.cnblogs.com/lonelyxmas/p/12060869.html

      有三种解决方式:第一种:在处理文件的Action 中添加:  

    var syncIOFeature = HttpContext.Features.Get<IHttpBodyControlFeature>();
    if (syncIOFeature != null)
    {
        syncIOFeature.AllowSynchronousIO = true;
    }

      第二种:或者在Startup.cs 中注册

     public void ConfigureServices(IServiceCollection services)
            {
                // If using Kestrel:
                services.Configure<KestrelServerOptions>(options =>
                {
                    options.AllowSynchronousIO = true;
                });
    
                // If using IIS:
                services.Configure<IISServerOptions>(options =>
                {
                    options.AllowSynchronousIO = true;
                });
    }

      第三种:(不太理解。。。)

                Request.EnableBuffering();
                using (var reader = new StreamReader(Request.Body, encoding: Encoding.UTF8))
                {
                    var body = reader.ReadToEndAsync();
                    // Do some processing with body…
                    // Reset the request body stream position so the next middleware can read it
                    Request.Body.Position = 0;
                }

      

  • 相关阅读:
    前端 network
    C语言的安装及使用
    c语言
    mongodb
    大型网站--负载均衡架构
    双机热备ROSE HA工作原理
    Linux vmstat命令实战详解
    管理员必备的20个Linux系统监控工具
    linux top命令详解
    linux命令TOP参数load average详解[转]
  • 原文地址:https://www.cnblogs.com/skyheaving/p/12641697.html
Copyright © 2020-2023  润新知