Reputation: 759
Hub code:
private readonly IHubContext<IMyHubClient> _context;
public MyHub(IHubContext<IMyHubClient> context)
{
_context = context;
}
public override Task OnConnected()
{
string userName = Context.User.Identity.Name;
string connectionId = Context.ConnectionId;
//some code to store connected user info
return base.OnConnected();
}
Client code:
$.connection.myHub.client.connected = function() { alert('1'); };
$.connection.myHub.client.disconnected = function() { alert('2'); };
$.connection.hub.start()
.done(function(){ console.log('Now connected, connection ID=' + $.connection.hub.id); })
.fail(function(){ console.log('Could not Connect!'); });
Client succesfully connects to hub and js callbacks are working. But server-side OnConnected method never fires. What can be the problem?
Upvotes: 0
Views: 2221
Reputation: 15234
Is MyHub
getting constructed? I doub't SignalR is able to supply the IHubContext<IMyHubClient>
parameter. If you add a parameterless constructor or remove the existing one, your code should work.
Upvotes: 2