当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net core 3.1 中Synchronous operations are disallowed. Call FlushAsync or set AllowSynchronousIO to true instead

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

2020年04月06日  | 移动技术网IT编程  | 我要评论

翟家慧,结婚当天遭挖苦,胡歌白冰公开恋情

     在进行 asp.netcore.mvc  文件上传时,后台无法正常读取文件流保存,出现:synchronous operations are disallowed. call writeasync or set allowsynchronousio to true instead.

    

 

 

   查找资料,发现需要添加允许条件,才可以; 感谢:

  有三种解决方式:第一种:在处理文件的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;
            }

 

  

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网