如何从 SignalR 中的 IHubContext 获取当前用户?

How to get current user from IHubContext in SignalR?

假设在某些 class 库中我可以访问特定的 HubContext:

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

如何访问当前经过身份验证的 .User 属性?

你不能。 GetHubContext 方法通常用于从后台线程向客户端(或 many/all 客户端)发送消息,因此根据定义不会有 SignalR 用户支持它。