Search code examples
signalrsignalr-hub

How to get current user from IHubContext in SignalR?


Suppose in some class library I have access to a specific HubContext:

IHubContext ctx = connectionManager.GetHubContext<MyAwesomeHub>();

How do I get access to the current authenticated .User property?


Solution

  • You can't. The GetHubContext method is normally used for sending messages from a background thread to a client (or many/all clients) so by definition won't have a SignalR user backing it.