Coffka
Coffka

Reputation: 759

Signalr 2.1.1 OnConnected not firing even with client callbacks

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

Answers (1)

halter73
halter73

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

Related Questions