I have a basic MVC application which is integrated with signal R. I'm tracking online users using this application.
Following is my Hub class
public class UserHub : Hub { static long counter = 0;
public override Task OnConnected()
{
//Update Count when User is connected
counter = counter+1;
Clients.All.UpdateCount(counter);
return base.OnConnected();
}
public override Task OnDisconnected(bool stopCalled)
{
counter = counter-1;
Clients.All.UpdateCount(counter);
return base.OnDisconnected(stopCalled);
}
}
Following is my javascript code
$.connection.hub.logging = true;
//setup hubs
var userHub = $.connection.userHub;
$.connection.hub.start().done(function () {
});
//function to recieve data from server
userHub.client.UpdateCount = function (count) {
$('#counter').text(count);
}
I have registered the in startup.cs class as well.
The problem is signalr Is throwing an error "SignalR: No hubs have been subscribed to. " When I refresh the page like 5 times, then the signal r is connected to hub and data is getting pulled.
Did anyone face this issue?
Any help is appreciated.
Thank you