Please note that the SignalR interface has changed several times since this question was asked. It is likely that some answers will become obsolete. This does not mean that they should be skipped, as they were correct at the time of writing.
There is another updated answer for this, as shown in the SignalR Wiki
FROM#
Public ActionResult MyControllerMethod() { var context = GlobalHost.ConnectionManager.GetHubContext<MyHub>(); context.Clients.All.methodInJavascript("hello world"); // or context.Clients.Group("groupname").methodInJavascript("hello world"); }
vb.net
Public Function MyControllerMethod() As ActionResult Dim context = GlobalHost.ConnectionManager.GetHubContext(Of MyHub)() context.Clients.All.methodInJavascript("hello world") '' or context.Clients.Group("groupname").methodInJavascript("hello world") End Function
Update
This code has been updated. For changes, run http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-server .
If you are using a DI container
If you use a DI container to connect hubs, get the IConnectionManager
from your container and call GetHubContext
in this connection manager.
Tim B James Jun 19 2018-12-12T00: 00Z
source share