问题
I've run into a situation where I need multiple SignalR hubs (at least 2) with different configurations.
Currently with v1.1.0 I can only do things like the following which configures all hubs:
GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(30);
Is it possible to set different configurations for multiple hubs?
回答1:
All hubs share the same connection object therefore they all share the same configuration.
If you want to have 1 server but multiple connection configurations for hubs you can do the following:
app.MapHubs(yourPathToConnectionWithConfigurationA, new HubConfiguration
{
Resolver = MyResolverWithConfigurationA
});
app.MapHubs(yourPathToConnectionWithConfigurationB, new HubConfiguration
{
Resolver = MyResolverWithConfigurationB
});
Therefore when you want to use configuration A you connect to that server end point and when you want to connect to endpoint B you connect to that endpoint. Keep in mind the hubs will not share clients/connections across the two configurations even though the hubs will be on both.
来源:https://stackoverflow.com/questions/17623962/multiple-signalr-hubs-with-different-configurations