How to use a SignalR hub instance outside of hubpipleline

I use SignalR to send messages to all my clients. I need to trigger a translation outside my hub class, for example, something like below:

var broadcast = new chatHub(); broadcast.Send("Admin","stop the chat");

I get an error like:

Using a Hub instance not created by HubPipeline is not supported.

+63
signalr signalr-hub
Feb 28 '13 at 5:26
source share
1 answer

You need to use GetHubContext :

 var context = GlobalHost.ConnectionManager.GetHubContext<chatHub>(); context.Clients.All.Send("Admin", "stop the chat"); 

This is described in more detail at http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-server#callfromoutsidehub .

+105
Feb 28 '13 at 5:39
source share
— -



All Articles