The SignalR context helps us to understand where we are and who is making the request. It is made available through the Context property of the Hub class. In it, you will find the following properties:
- Connection (HubConnectionContext): This is low-level connection information; you can get a reference to the current HttpContext from it (GetHttpContext()) as well as metadata stuff (Metadata) and it is possible to terminate the connection (Abort()).
- ConnectionId (string): This is the one and only connection ID that uniquely identifies a client on this hub.
- User (ClaimsPrincipal): This is the current user (useful if using authentication) and all of its claims.
The Context property is available when any of the hub methods is called, including OnConnectedAsync and OnDisconnectedAsync. Do not forget that for a context, a user is always identified by its ConnectionId; only if you use authentication...