#Accident scene
In the asp.net core web API project, when reading the stream stream of request.body, the following error is reported:
Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.
The code is as follows:
var request = context.HttpContext.Request;
if (request.Method == "POST")
{
request.Body.Seek(0, SeekOrigin.Begin);
using (var reader = new StreamReader(request.Body, Encoding.UTF8))
{
var data = reader.ReadToEnd();
}
}
#Solution
The synchronous reading method of the body needs to be configured in configureservices to allow synchronous reading of IO streams. Otherwise, an exception may be thrown. Call readasync or set allowsynchronous IO to true instead.
configure according to the managed service used or directly use the asynchronous reading method.
public void ConfigureServices(IServiceCollection services)
{
//other
services.Configure<KestrelServerOptions>(x => x.AllowSynchronousIO = true)
.Configure<IISServerOptions>(x=>x.AllowSynchronousIO = true);
}
Read More:
- Springboot connects to the database error: testWhileIdle is true, validationQuery not set
- ES Error: Alternatively, set fielddata=true on [How to Solve]
- [Solved] Opencv Compile Error: (CMake Error: The following variables are used in this project, but they are set to not)
- How to Fix IIS7.5 Disallowed Parent Path Error
- AAR Call Error: only jar-type local dependencies are supported
- Stream to MemoryStream to solve Stream.Length error report This stream does not support search operations
- Widgets are not available. Please install widgetsnbextension or ipywidgets 4.0
- calico Error: Calico requires net.ipv4.conf.all.rp_filter to be set to 0 or 1
- [Solved] Springboot WARNING: All illegal access operations will be denied in a future release
- Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment
- Tidb-dm Synchronous error: binlog checksum mismatch, data may be corrupted
- [Solved] Failed assertion: line 3180 pos 12: ‘debugNeedsPaint‘: is not true
- Vue+TS main.ts error: unused expression, expected an assignment or function call
- [Solved] MindSpore Error: `half_pixel_centers`=True only support in Ascend
- RabbitMQ Configuration File Error: publisher-confirms=true [Solved]
- [Solved] Using `babel-preset-react-app` requires that you specify `NODE_ENV` or `BABEL_ENV` environment variables. Valid values are “development”, “test”, and “production”. Instead, received: undefined.
- Android 10 open file exception open failed: eacces (permission denied) android:requestLegacyExternalStorage= “true“
- Resolve InsecurePlatformWarning: A true SSLContext object is not available.
- Error (17) solves the problem of losing the request header of multithread asynchronous feign call