asp.net – SignalR 2.0超时连接
发布时间:2020-12-16 00:13:33 所属栏目:asp.Net 来源:网络整理
导读:我正在使用SignalR.But有一个关于超时的问题. 几分钟后超时消失,无法正常工作. 如何在SignalR 2.0中设置超时连接? 解决方法 您可以在Owin Startup类中使用以下配置. // Make long polling connections wait a maximum of 110 seconds for a // response. Wh
我正在使用SignalR.But有一个关于超时的问题.
几分钟后超时消失,无法正常工作. 如何在SignalR 2.0中设置超时连接? 解决方法
您可以在Owin Startup类中使用以下配置.
// Make long polling connections wait a maximum of 110 seconds for a // response. When that time expires,trigger a timeout command and // make the client reconnect. GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(40); // Wait a maximum of 30 seconds after a transport connection is lost // before raising the Disconnected event to terminate the SignalR connection. GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(30); // For transports other than long polling,send a keepalive packet every // 10 seconds. // This value must be no more than 1/3 of the DisconnectTimeout value. GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(10); //Setting up the message buffer size GlobalHost.Configuration.DefaultMessageBufferSize = 500; 此外,当您希望始终将客户端连接到服务器时,可以尝试在disconnect hub事件中连接它. var tryingToReconnect = false; $.connection.hub.disconnected(function () { //TODO: write the logic to reconnect to server. if(!tryingToReconnect) { // notifyclient about disconnection setTimeout(function() { $.connection.hub.start(); },5000); // Restart connection after 5 seconds. } }); $.connection.hub.reconnecting(function() { tryingToReconnect = true; console.log("reconnecting..."); }); $.connection.hub.reconnected(function() { tryingToReconnect = false; console.log("Reconnected"); }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – ASP.NET MVC 3中字典的隐藏输入
- asp.net – 如果我将ValidateRequest设置为false,这不是很危
- asp.net-core – 为什么这违反了类型参数’TUser’的约束?
- asp.net-mvc – 使用局部视图渲染以逗号分隔的项目集的最优
- asp.net-mvc-3 – MVC 3使用RenderPage更改视图中的模型
- asp.net-mvc – 如何在我自己的自定义助手中使用ASP.NET MV
- ASP.NET Core 运行原理剖析
- asp.net core系列 43 Web应用 Session分布式存储(in memory
- asp.net – 使用json仅序列化对象的一部分
- asp.net – VB.NET 2.0:代码中的URL来自哪里?
推荐文章
站长推荐
- asp.net-mvc – Asp.Net Mvc JQuery ajax输入参数
- asp.net – SQL – 两个不同长度的字符串之间的相
- asp-classic – 使用TFS 2010“构建”经典ASP
- 如何使用UTC时间(asp.net和ajax)向用户呈现本地时
- asp.net-mvc – 后退按钮不会导致回发到MVC中的控
- asp.net-mvc – 具有键’XXX’的ViewData项的类型
- WeihanLi.Npoi 1.10.0 更新日志
- 在asp.net httpContext.Cache中存储/检索项目最有
- asp.net – ASP .Net VNext和Owin
- asp.net-mvc – 你如何指定在列表框中显示多少项
热点阅读