2013-07-11 96 views
1

我在使用SignalR(1.1.2)试图创建一个基本的实时聊天设置并花了大约一周的时间(包括通过SignalR源码进行拖网)后遇到了一些问题。什么我可以尝试结束...SignalR连接问题

我有(我想)一个相当复杂的SignalR设置包括:

  • 负载均衡的服务器
  • Redis的消息总线
  • 每两个服务器上的网站(ASP.NET Webforms VB.NET桌面站点和MVC3 C#mobi le site)

每个站点都包含自身的集线器和其他站点,因此每个页面都可以向每个站点发送消息。

展望Chrome检查(在移动网站上的这个例子),轮毂都加载,对于移动的谈判步骤是成功的,但3秒钟,到错误后,连接尝试失败:

的EventSource的响应具有不是“文本/事件流”的MIME类型(“text/html”)。中止连接。

这当然是我们的Microsoft.Owin.Host.SystemWeb后的自定义500错误页面已抛出:

的连接ID的格式不正确。

一旦发生这种情况,大部分的时间,那么这将陷入某种奇怪的循环,其中,将继续抛出数百个这样的错误,并欢送很多坪接着是longPolling的连接

解决方案在我的开发环境(单个IIS实例)中工作得很好,但移动到负载平衡测试环境是我看到错误的地方。

我不知道是否还有其他我可以添加的内容,但可以帮助但我很乐意添加它。


我已经添加了以下到Web.config文件在这两个网站:

<validation validateIntegratedModeConfiguration="false"/> 
<modules runAllManagedModulesForAllRequests="true"/> 

<add name="Access-Control-Allow-Origin" value="*"></add> 
<add name="Access-Control-Allow-Headers" value="Content-Type" /> 

在Global.asax文件有:

protected void Application_Start() 
{ 
    AreaRegistration.RegisterAllAreas(); 

    RegisterGlobalFilters(GlobalFilters.Filters); 
    RegisterRoutes(RouteTable.Routes); 

    RedisScaleoutConfiguration redisConfig = new RedisScaleoutConfiguration([redisIP], [port], String.Empty, "Name"); 
    redisConfig.Database = 9; 
    GlobalHost.DependencyResolver.UseRedis(redisConfig); 
} 

public static void RegisterRoutes(RouteCollection routes) 
{ 
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
    HubConfiguration hubConfig = new HubConfiguration(); 
    hubConfig.EnableCrossDomain = true; 
    hubConfig.EnableDetailedErrors = true; 
    RouteTable.Routes.MapHubs(hubConfig); 

    <snip> 
} 

我的JS代码是:

function setUpSignalR() { 
     //Set up the connections 
     webConnection = $.hubConnection(pageInfo.webUrl); 
     mobConnection = $.hubConnection(pageInfo.mobUrl); 

     //Get the hubs for web and mobile 
     webHub = webConnection.createHubProxies().messagingHub; 
     mobHub = mobConnection.createHubProxies().messagingHub; 

     //Hook up the call back functions 
     <snip> 

     //Now, start it up! 
     mobConnection.logging = true; 
     mobConnection.start().done(function() { 
      mobHub.server.joinConversation(pageInfo.conversationGuid, "mobile").fail(function (error) { console.log('JoinConversation for mobile connection failed. Error: ' + error); }); 
      webConnection.start().done(function() { 
       webHub.server.joinConversation(pageInfo.conversationGuid, "mobile").fail(function (error) { console.log('JoinConversation for web connection failed. Error: ' + error); }); 
      }); 
     }); 
    } 

回答

1

SignalR troubleshooting document

"The connection ID is in the incorrect format" or "The user identity cannot change during an active SignalR connection" error

This error may be seen if authentication is being used, and the client is logged out before the connection is stopped. The solution is to stop the SignalR connection before logging the client out.