zoukankan      html  css  js  c++  java
  • .net core 3.1 Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead

    刚才使用angularjs向后台post数据时候,发现这个问题,.net core 3.1 读取post过来的数据流的时候被阻止了。大致了解了下:3.0中默认禁用了AllowSynchronousIO,如果想同步读取body则需要在ConfigureServices中配置允许同步读取IO流。

    我这边了解的解决方案有了如下两种

    1、在读取数据流的Action中添加

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

    2、在Startup.csConfigureServices方法中添加如下代码:

    1 services.Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(x => x.AllowSynchronousIO = true)
    2         .Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);

    我用的是第二种,第一种没有试,不过根据经验应该没问题,只是每个action都写一遍,,会比较繁琐,所以果断选择了第二种。

  • 相关阅读:
    主机连接不上虚拟机或虚拟机桥接没有网络
    asp web 报表
    heart or house?
    CPointer
    Raid
    Dos for by 随风
    不支持uri格式
    FabEdge V0.4 新特性:支持多集群通讯
    运维监控
    /etc缩写
  • 原文地址:https://www.cnblogs.com/PrintY/p/13945996.html
Copyright © 2011-2022 走看看