SignalR - adding hubs at runtime

2019-03-05 02:42发布

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条回答
姐就是有狂的资本
2楼-- · 2019-03-05 03:17

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

查看更多
登录 后发表回答