Azure SignalR Context Within Constructor

113 views Asked by At

Is there a way to get the user Id within a AzureSignalR Process? Like below I want to get that User Id and if I dont use AzureSignalR I can get it through the HttpContext but in the case of AzureSignalR it seems that only in the actual methods themselves i cant get that ID meaning I cant do anything in my app since i need that User ID

public class BaseHub : Hub
{

    public BaseHub()
    {
        var userId = this.Context.User.Claims.FirstOrDefault(x => x.Type == "user_id")?.Value;
    }
}
1

There are 1 answers

0
Chauncy Zhou On
public class NameUserIdProvider : IUserIdProvider
{
    public string GetUserId(HubConnectionContext connection)
    {
        return connection.User?.Identity?.Name;
    }
}

Please refer to this doc.