我有一个Angular.js应用程序,我正在移植到.NET核心。
它在以前版本的.NET核心3预览版中运行良好。
但是,升级到最新3.3之后,一些get请求将返回此错误:
InvalidOperationException:不允许同步操作。调用WriteAsync或将AllowSynchronousIO设置为true。
我不明白为什么这种情况只发生在一些请求中,而不存在于其他请求中。
我相信默认情况下,Angular.js会执行异步:xhr.open(方法、url、true);
有人能解释一下这件事吗?
发布于 2019-03-08 11:31:18
这个问题在这里描述:https://github.com/aspnet/AspNetCore/issues/8302
目前的解决办法是在AllowSynchronous中手动将startup.cs设置为true;
// Startup.ConfigureServices
services.Configure<IISServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
发布于 2019-05-06 19:56:32
值得注意的是,如果您直接托管在kestrel上,那么您的Program.cs应该有适当的ConfigureKestrel调用
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureKestrel((context, options) =>
{
options.AllowSynchronousIO = true;
})
发布于 2020-03-13 20:55:20
对于特殊的方法,可以禁用它。
var syncIOFeature = HttpContext.Features.Get<IHttpBodyControlFeature>();
if (syncIOFeature != null)
{
syncIOFeature.AllowSynchronousIO = true;
}
或禁用所有应用程序范围。
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureKestrel((context, options) =>
{
options.AllowSynchronousIO = true;
})
或在服务配置启动中。
services.Configure<IISServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
https://stackoverflow.com/questions/55052319
复制相似问题