Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

signalR - getting username

People also ask

How do you authenticate a SignalR hub?

In a browser-based app, cookie authentication allows your existing user credentials to automatically flow to SignalR connections. When using the browser client, no additional configuration is needed. If the user is logged in to your app, the SignalR connection automatically inherits this authentication.

How do I reconnect my SignalR?

Handle the disconnected event to display a message when an attempt to reconnect has timed out. In this scenario, the only way to re-establish a connection with the server again is to restart the SignalR connection by calling the Start method, which will create a new connection ID.


When using SignalR hubs you can use the HubCallerContext.User property to:

Gets the user that was part of the initial http request.

So try it with:

public Task Join()
{
    string username = Context.User.Identity.Name;
    //find group based on username
    string group = getGroup(username)
    return Groups.Add(Context.ConnectionId, group);
}