This just come up and after searching and testing it like to Fix SignalR OnDisconnected if not working is to implement on the client at least one method so that this method will be called. Think of it like a requirement.
Example for the SignalR residing on the same server
<!– Reference to jQuery –>
<!– Reference to SignalR –> <script src=”~/hubs/signalr“></script>
var onlineHubProxy = $.connection.onlineHub;
Most of us who are using .Net as our Programming language use Signalr as our Real-Time Framework. And we implement OnDisconnect in most cases to catch clients that have been disconnected. Since then there were no parameter included as an Overload of the said method. Lately on the latest releases by the Signalr team they have included an Overload so that we can distinguish what triggers the disconnection and help us manage our Apps behavior to it.
With this said I have one experience that I want to share as this may also frustrate some people who are counting connected users and having a problem that when their app have multi workers (Web Garden) they app somehow always trigger OnDisconnect even if the user is still connect. So I want to share this findings on how to properly address it.
Make sure that the App is using a Backplane to manage connection on your hub so that the connections are shared on all threads/servers. I use SQLServer.
Make sure to use the Database on counting your list of connection and tagging who is who. Because in memory List even its static will not be shared on a different server (obviously).
Make sure to trigger disconnection action when the OnDisconnect is called with the stopCalled is equal to true.
Let me highlight what is stopCalled is equal to true means.
It returns true if the method on the connection to close is trigger
It returns true if the browser is called
It returns false if the timeout has been met
Hope this instructions will help you manage your site as it help me on our projects.
We are glad to invite you to our first Free service product, OpenCast. OpenCast is an online broadcasting websites that aim to help people broadcast freely and openly. The website is created using ASP.Net MVC, Entity Framework, SignalR, & OpenTok.