如何在ASP.NET MVC 4中使用Signalr V2 Beta [英] How to use signalr v2 beta in asp.net mvc 4
本文介绍了如何在ASP.NET MVC 4中使用Signalr V2 Beta的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在v2之前:
RouteTable.Routes.MapHubs();
在v2中,MapHubs不再存在. Wiki说要添加一个Startup类和一个Configuration方法以及对app.MapHubs()的调用.
In v2, MapHubs does not exist anymore. The wiki says to add a Startup class and a Configuration method and a call to app.MapHubs().
namespace MyAssembly
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
//Before v2
//RouteTable.Routes.MapHubs();
app.MapHubs();
}
}
}
但是永远不会调用该方法,不会发生错误,并且...没有设置集线器.
But the method is never called, no error occurs, and ... no hub are setup.
我想有些代码要添加到global.asax.cs
I suppose there is some code to add to global.asax.cs
秘密是什么?
推荐答案
删除了不相关的行.
解决方案!
<appSettings>
<add key="owin:AppStartup" value="MyNameSpace.Startup, MyNameSpace" />
</appSettings>
plus同时更新了MVC4(不是预发行版,而是最新的稳定版本)和SignalR/owin nuget.
plus update both MVC4 (not to prerelease, but to latest stable version) and SignalR/owin nugets.
加上js客户端中的修复错误:
plus fix bugs in js client :
- 如果disconnectTimeout = 999000,则将其禁用.必须通过以下方式在服务器端进行设置:GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(999); 注意:服务器端不能将值设置为< 6(如果DisconnectTimeout< 6,信号器将引发异常).因此,请使用此魔术数字.
- webSockets:在sockettransport中设置connection.socket = null,否则(手动)停止调用后,启动调用将失败
- serverSentEvents:防止在卸载窗口时由重新连接尝试引起的错误
- chrome如果信号器中心URL不可用(暂时)失败,则异常失败:与其放弃,请尝试使用下一个可用协议/尝试重新连接.
- if disconnectTimeout=999000 then it is disabled. Must be set server-side with: GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(999); note: server side can not set a value < 6 (signalr throws an exception if DisconnectTimeout < 6). So use this magic number.
- webSockets: set connection.socket = null in sockettransport, otherwise the call to start fails after a (manual) call to stop
- serverSentEvents: prevent error caused by a reconnection attempt when the window is unloading
- chrome fails with exception if signalr hub url not available (temporarily) : Instead of giving up try the next available protocol / try to reconnect.
这篇关于如何在ASP.NET MVC 4中使用Signalr V2 Beta的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文