Use of /signalr/ping call when using long polling

*爱你&永不变心* 提交于 2019-12-10 02:41:57

问题


I'm using long polling with SignalR. I've found that user session ends (ASP.NET Session_End is being called) right after singalr based webpage makes /signar/ping request (as shown in this screenshot). I went through http://www.asp.net/signalr/overview/signalr-20/hubs-api/handling-connection-lifetime-events but couldn't figure out clear answers following questions.

  1. How to keep ASP.net user session alive from a signalr client webpage?
  2. What is the actual purpose of /ping?
  3. Is the timing for this /ping call configurable?

回答1:


The entire purpose of the /signalr/ping request is to keep ASP.NET sessions alive. By making requests on a regular interval shorter than the session timeout, the session should never expire since the server should reset the timeout on each request.

In the case of the long polling transport, this is probably unnecessary since SignalR will force a new long poll at least every 110 seconds given the default configuration. Even so, SignalR will make a ping request every 5 minutes by default no matter what transport is in use. This 5 minute interval is small enough to deal with ASP.NET's default 20 minute session timeout.

You can change the 5 minute ping interval to a custom value in your call to $.connection.hub.start like so:

// Configure SignalR to ping the server every minute
$.connection.hub.start({ pingInterval: 60000 })//...

The default pingInterval is 300000 milliseconds (5 minutes). You can disable the ping by setting pingInterval to null.



来源:https://stackoverflow.com/questions/25597468/use-of-signalr-ping-call-when-using-long-polling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!