how to get SignalR user connection id out side the hub class?

Yep. You can use $.connection.hub.id.


This works for me:

var hub = $.connection.someHub;
// After connection is started
console.log(hub.connection.id);

For a .NET Client it is on the Connection object, inherited by HubConnection.

Connection.ConnectionId

So typically can be found on

hubConnection.ConnectionId

There's another way also, you can get connection id into your controller from hub by invoking a method of hub and you can return the required ID from there.

Controller Code

var HubContext = GlobalHost.ConnectionManager.GetHubContext<"ChatHub">(); //`ChatHub` can be your Hub Name
ChatHub HubObj= new ChatHub();
var RequiredId= HubObj.InvokeHubMethod();

Code inside Hub

public string InvokeHubMethod()
{
     return "ConnectionID"  //ConnectionID will the Id as string that you want outside the hub
}