.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
相关产品推荐
相关产品推荐

