iis - IIS上的Blazor服务器端应用程序经常断开WebSocket连接

标签 iis websocket blazor blazor-server-side

我在IIS 10上发布了Blazor服务器端应用程序。
当浏览到任意页面并在一分钟左右(有时只有45秒,有时是一到两分钟之间)后让其空闲时,

Attempting to reconnect to server ...



出现几秒钟。
在浏览器控制台中,日志记录显示

Error: Connection disconnected with error 'Error: Server timeout elapsed without receiving a message from the server.'.



或者

Information: Connection disconnected.



由于这似乎是超时问题,因此我在 startup.cs 中为 ConfigureServices 添加了以下选项
services.AddServerSideBlazor()
                .AddHubOptions(options =>
                {
                    options.ClientTimeoutInterval = TimeSpan.FromMinutes(10);
                    options.KeepAliveInterval = TimeSpan.FromSeconds(3);
                    options.HandshakeTimeout = TimeSpan.FromMinutes(10);
                });

但是,这不能解决问题。

我还转到了IIS中站点的高级设置,并将连接超时从默认的120秒增加到了600秒。这也没有帮助。

这些频繁的断开连接仅发生在IIS 10托管的实时站点上。
如果我使用Visual Studio在本地启动应用程序,则连接是稳定的。

我所缺少的任何提示将不胜感激!

更新:

正如来自火星的@agua所建议的那样,我在下面的评论中更改了运输类型
app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapBlazorHub(options => { options.Transports = HttpTransportType.LongPolling; });
                endpoints.MapFallbackToPage("/_Host");
            });

进行此更改后,连接仍然关闭。控制台日志显示

Information: (LongPolling transport) Poll terminated by server.



我还尝试了 HttpTransportType.ServerSentEvents ,它根本不起作用,但是会出现此错误

Error: Failed to start the connection: Error: Unable to connect to the server with any of the available transports. ServerSentEvents failed: Error: 'ServerSentEvents' does not support Binary.



更新2:

IIS配置为使用HTTP 1.1
我尝试更改为HTTP/2,但这并没有更改有关断开连接的任何内容。

最佳答案

试试看..

            app.UseEndpoints(endpoints =>
            {
//other settings
.
.
endpoints.MapBlazorHub(options => options.WebSockets.CloseTimeout = new TimeSpan(1, 1, 1));
//other settings
.
.
});

关于iis - IIS上的Blazor服务器端应用程序经常断开WebSocket连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60057826/

相关文章:

iis - 将ASP.NET Web API部署到IIS服务器

python - 为什么我从 urllib2 发出的请求被 Apache2 延迟了?

node.js - WebSocket通过Amazon ELB或直接通过WebSocket(远程IP问题)

java - 如何在 Java Spring Tomcat 中快速关闭无响应的 websocket?

blazor - 通知 EditContext 该字段已更改以进行 Blazor 验证

c# - Sharepoint 事件接​​收器安全异常

asp.net - SpecifiedPickupDirectory在服务器上的用户查看之前不会创建文件

angular - 有没有办法知道 rxjs websocket 是否打开

javascript - 与 Blazor 进行 JS 互操作时找不到窗口的属性

c# - 如果变量更改发生在单独的线程上,Blazor 不会检测到变量更改