SignalR - adding hubs at runtime

蓝咒 提交于 2019-12-20 06:19:00

问题


I have a working SignalR application, my global.asax.cs does all the usual MapHubs() etc, and I'm using a custom IAssemblyLocator which also loads in-memory assemblies as well as referenced assemblies. The two hubs I have are created at runtime in in-memory assemblies, and this works fine - hubs can push messages to clients etc.

At some point after the application has started, I want to add another hub at run time which will sit in it's own in-memory assembly, and make it appear in the signalr/hubs/ file.

How do I do this?

Calling MapHubs again results in an error because I already have the route defined. Removing the route (which I've only managed to do using RouteTable.Routes.Remove(RouteTable.Routes[0]) so far, and obviously isn't ideal) doesn't seem to work.

Is there a nice way to do this?


回答1:


Use the alternate syntax instead of using the static signalr/hubs file since it will never update:

http://www.asp.net/signalr/overview/hubs-api/hubs-api-guide-javascript-client#genproxy



来源:https://stackoverflow.com/questions/17070378/signalr-adding-hubs-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!