You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Blazor Web模板在Kestrel服务器加载卡顿求助

Kestrel服务器页面加载不全问题求助

当页面内容增多(如在Layout中添加HTML模板)时,IIS Express与Kestrel服务器均触发以下错误:
InvalidOperationException: Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.

在Program类中添加如下配置后,IIS Express的问题得以解决,但Kestrel仅能加载部分页面,剩余内容无法显示:

builder.Services.Configure<IISServerOptions>(options => {options.AllowSynchronousIO = true; }); 
builder.Services.Configure<KestrelServerOptions>(options => {options.AllowSynchronousIO = true; });

由于需部署至Linux环境,必须使用Kestrel服务器,现寻求该问题的解决方案。

预期行为

在Kestrel中正常显示完整页面

复现步骤

创建包含以下代码的页面:

@page "/test"
@layout EmptyLayout
<PageTitle>Test Page</PageTitle>
<h1>Test</h1>
<p>This is test.</p>

@if (_isLoading)
{
    <p>
        <em>Loading...</em>
    </p>
}
else
{
    @foreach (var item in _messageList)
    {
        @item
    }
}

@code {
    private readonly List<string> _messageList = new();
    private bool _isLoading = true;

    protected override async Task OnInitializedAsync()
    {
        for (var i = 0; i < 2000; i++)
        {
            _messageList.Add($"This is Test : {i}  ");
        }
        _isLoading = false;
    }
}

异常情况

  • IIS Express运行正常
  • Kestrel加载页面时仅显示部分内容,剩余内容无法加载(页面加载不全卡顿)

.NET版本

8.0.0-preview.7.23375.9

内容的提问来源于stack exchange,提问作者Masih

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 15:37:11