I can't send a notification message to a specific user from the controller.
My controller:
public class SomeController : ControllerBase
{
private readonly IHubContext<NotificationHub> _hubContext;
public SomeController(IHubContext<NotificationHub> hubContext)
{
_hubContext = hubContext;
}
public async Task SomeMethod()
{
//it works
await _hubContext.Clients.All.SendAsync("sendMessage", msg);
//it doesn't work
await _hubContext.Clients.User(userId).SendAsync("sendMessage", msg);
//it also doesn't work
await _hubContext.Clients.Client(userId).SendAsync("sendMessage", msg);
}
}
Unfortunately, IHubContext has some imperfections. In the Clients property is available only Clients. All - that is, we can send a message only to all clients and there are no such properties as Other or Caller that are available in the hub class. Also, we cannot get a connection id from IHubContext.
Is there some else method to do it? Or is it possible only with SQL Dependency?