Paul
Paul

Reputation: 705

acess signalr hub class methods from code behind

Is it possible to execute a public method declared in a signalr hub from the code behind of a webforms page?

I have found examples of how to send a message to the client from the code behind using

var context = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();

context.Clients.All.exampleMethod();

but i would like to access a public method in the hub for example to return a set of client ids associated with a user from a ConcurrentDictionary or datatable.

Does anybody know if this is possible and if so how to go about this without broadcasting a message to the client and back again.

Upvotes: 0

Views: 2240

Answers (1)

Dave Lawrence
Dave Lawrence

Reputation: 3929

You should register the clients connection ids when they connect. Once you have that id; you can send a message to that client using

var context = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
context.Clients[connectionid].exampleMethod();

Forgive me if I haven't got that 100% right but I'm on the train

This link should give you some help... http://www.tugberkugurlu.com/archive/mapping-asp-net-signalr-connections-to-real-application-users

Upvotes: 0

Related Questions