问题描述
ASP.NET核心服务器,AllowSynchronousIO
设置为false
ASP.NET core server, AllowSynchronousIO
is set to false
new WebHostBuilder()
.UseKestrel(options =>
{
options.AllowSynchronousIO = false;
})
在操作中,它输出一个JsonResult
In the action, it outputs a JsonResult
public async Task<IActionResult> SanityCheck()
{
Dictionary<string, string> dic = await GetDic();
return this.Json(dic);
}
它以异常结尾
我不能用AllowSynchronousIO=false
返回JsonResult吗?
Can't I return a JsonResult with AllowSynchronousIO=false
?
最好的问候
推荐答案
您可能会遇到以下问题: https://github.com/aspnet/AspNetCore/issues/8302
You might have the following problem: https://github.com/aspnet/AspNetCore/issues/8302
您可以在此处找到更多信息: https://github.com/aspnet/AspNetCore/Issues/7644
And you can find more info here: https://github.com/aspnet/AspNetCore/issues/7644
解决此问题之前的解决方法是允许同步IO.将其放入用于Kestrel或IIS的Startup.cs中:
A workaround until the issue is being solved is to allow Synchronous IO. Put this in Startup.cs for either Kestrel or IIS:
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;
});
}
这篇关于ASP.NET Core:不允许进行同步操作.调用WriteAsync或将AllowSynchronousIO设置为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!