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

在Action中解决措施:

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

 也可以这样:

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

            // If using IIS:
            services.Configure(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;
            }

 

你可能感兴趣的:(asp.net core 3.1 中Synchronous operations are disallowed. Call FlushAsync or set AllowSynchronousIO to true instead)