本文介绍了使用自定义解析器时SignalR更改DisconnectTimeout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在运行SignalR时使用自定义解析器以利用依赖项注入.但似乎我的DisconnectTimeout&此后不使用KeepAlive值.我已经阅读了一些注释,这些注释将忽略配置,然后使用自定义解析程序.但是设置GlobalHost.DependencyResolver应该可以解决问题.但是更改后,断开连接的超时似乎仍然是30秒.
I'm using a custom resolver when running SignalR to make use of dependency injection.But it seems like my DisconnectTimeout & KeepAlive values aren't used after this. I've read some comments that the Configuration is ignored then using a custom resolver. But settings the GlobalHost.DependencyResolver should do the trick. But after changing it, the disconnect timeout still seems to be 30 seconds..
代码:
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);
});
我在做错什么或没有在想什么吗?
Is there anything I'm doing wrong or not thinking about?
推荐答案
以下代码对我有用
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);
}
这篇关于使用自定义解析器时SignalR更改DisconnectTimeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!