一段时间后会失去连接

一段时间后会失去连接

本文介绍了使用SignalR集线器,一段时间后会失去连接-为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的SignalR应用程序中,按预期在页面上触发了回调.如果该页面保留了一段时间,则在刷新该页面之前,将不再在该页面上调用回调.

In my SignalR app, callbacks are fired as expected on a page. If the page is left for some time, callbacks are no longer invoked on that page until it is refreshed.

我怀疑这可能是由于该站点的会话即将到期(使用客户端的会话ID来调用客户端通知)所致.

I suspect that this could be due to the site's session expiring (using a client's session ID to invoke a client notification).

我在此处中阅读了有关KeepAlive功能的信息,并可以看到一些对此功能的引用在SignalR代码中.我不清楚是否需要实施客户端保持活动状态,如果需要,如何执行?

I read here about the KeepAlive functionality and can see some references to it in the SignalR code. I am unclear if a client-side keep-alive needs to be implemented, and if so, how?

推荐答案

我没有做任何实验或检查过文档,但是您的假设是合理的.由于种种原因,SignalR不支持会话.如果它不支持从会话读取,则可以合理预期它不会刷新会话过期时间.但是,如果您确实需要使用会话ID作为客户端ID(您不应该使用),则实现一种保持活动很容易.只需编写一些JS即可以最简单的方式调用服务器(例如,启用了Session的HTTP处理程序),而无需进行任何工作.它仅用于刷新会话到期时间.

I haven't made any experiments or checked the documentation but your assumption makes sense. SignalR does not support session for various good reasons. If it does not support reading from the session then it is reasonable to expect that it will not refresh the Session expiration time. However if you really need to use Session ID as the client ID (which you should not) then implementing a kind of keep alive is easy. Just write some JS to call the server (a Session enabled HTTP handler for example) in the simplest manner without doing any work. It will serve only to refresh the Session expiration time.

这篇关于使用SignalR集线器,一段时间后会失去连接-为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 03:26
查看更多