Use of /signalr/ping call when using long polling

Raj picture Raj · Sep 1, 2014 · Viewed 9.4k times · Source

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?

Answer

halter73 picture halter73 · Sep 3, 2014

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.