我在运行SignalR时使用自定义解析器来使用依赖注入。 但似乎我的DisconnectTimeout&此后不使用KeepAlive值。我已经阅读了一些注释,然后使用自定义解析器忽略配置。但设置GlobalHost.DependencyResolver应该可以解决问题。但是在更改之后,断开连接超时似乎仍然是30秒..
代码:
var resolver = new NinjectSignalRDependencyResolver(Program.kernel);
GlobalHost.DependencyResolver = resolver;
GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(9);
GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(3);
app.Map("/signalr", map =>
{
map.UseCors(CorsOptions.AllowAll);
var hubConfiguration = new HubConfiguration
{
Resolver = resolver,
EnableJSONP = true,
EnableDetailedErrors = true
};
map.RunSignalR(hubConfiguration);
});
有什么我做错了或没想过吗?
答案 0 :(得分:0)
以下代码适用于我
var wDependenctResolver = new SignalRUnityResolver(wUnityContainer);
GlobalHost.DependencyResolver = wDependenctResolver;
GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(30);
GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(6);
GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(2);
try
{
var hubConfiguration = new HubConfiguration
{
EnableDetailedErrors = true,
EnableJavaScriptProxies = true
};
appBuilder.MapSignalR("/signalr", hubConfiguration);
}
catch (Exception ex)
{
Console.WriteLine("Failed to initialize or map SignalR", ex);
}