简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM