SignalR:有时谈判请求返回404错误(负载平衡) [英] SignalR: Sometimes Negotiating requests returns 404 error (Load-balanced)

查看:2268
本文介绍了SignalR:有时谈判请求返回404错误(负载平衡)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用signalR 2.1.2,我推通知我的客户。
前端是负载平衡。
奇怪的是:有时工作,有时没有。它似乎没有什么做浏览器的类型。有时在IE有时它工作在Chrome中。首先,我认为运输的类型可能是问题,这就是为什么我降级的传输类型为长轮询,遗憾的是它并没有帮助:

I am using signalR 2.1.2 and I am pushing notifications to my client. The front end is load balanced. The weird thing is: Sometimes it works and sometimes it doesn't. It seems that it doesn't have anything to do with the type of browser. Sometimes it works in IE sometimes it works in Chrome. First I thought that the type of transport might be the problem, that's why I downgraded the transport type to long polling, unfortunately it didn't help:

客户端:

$.connection.hub.logging = true; // Enable SignalR logging

$.connection.hub.start({ transport: 'longPolling' }).done(function() {
     console.log("Connected, using transport method: " + $.connection.hub.transport.name);

        }).fail(function() {
            console.log("ERROR! Could not establish SignalR connection");
        });


        $.connection.hub.stateChanged(function(change) {

            if (change.newState === $.signalR.connectionState.disconnected) {
                console.log("State of SignalR connection changed to disconnected");                                       
            } else if (change.newState === $.signalR.connectionState.connected) {
                console.log("State of SignalR connection changed to connected");
            }
        });

$.connection.MessageHub.client.newIncoming = function(id) {
                // server call and that stuff
            }

服务器端:

[HubName("MessageHub")]
    public class MessageNotificationHub : Hub
    {
        // Methods that are implemented here, can be called by the client via ajax and broadcast to every other client

        public override Task OnConnected()
        {
            return base.OnConnected();
        }

    }

在服务器:

public void Notify(long id)
{
      var notifyHubContext = GlobalHost.ConnectionManager.GetHubContext<MessageNotificationHub>();
            notifyHubContext.Clients.All.newIncoming(id);
}

没有什么大不了的,只是看起来像另一个signalR样本。

No big deal, just looks like another signalR sample.

下面是错误消息,从日志:

Here are the error messages from the log:

SignalR:客户端订阅中心messagehub。
SignalR:与谈判'/applicationname/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22messagehub%22%...

SignalR: Client subscribed to hub 'messagehub'. SignalR: Negotiating with '/applicationname/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22messagehub%22%...

错误!无法建立连接SignalR

ERROR! Could not establish SignalR connection

SignalR:停止连接

SignalR: Stopping connection.

改为断开连接SignalR国家

State of SignalR connection changed to disconnected

解码URI的表示:
https://server/applicationname/signalr/negotiate?clientProtocol=1.4&connectionData=[{\"name\":\"messagehub\"}]&_=1426756354570

Decoding the URI shows: https://server/applicationname/signalr/negotiate?clientProtocol=1.4&connectionData=[{"name":"messagehub"}]&_=1426756354570

难道负载均衡的部分原因我所有的烦恼。

Is it possible that the load balancing part causes all my troubles.

我AP preciate您的帮助!
THX

I appreciate your help! Thx

推荐答案

我发现,这个问题是在web.config中缺少的机器密钥。因此,Web服务器A上创建的网络服务器比B有另一台机器的关键。 SignalR使用机器密钥来验证消息是否来自有效的发件人。
之后,我在web.config中添加的计算机密钥,其部署和关闭它的工作就像魅力的所有会话!

I found out, that the problem was the missing machine key in the web.config. Hence, the Webserver A created another machine key than webserver B has. SignalR uses the machine key to verify if the message is from a valid sender. After I added the machine key in the web.config, deployed it and closed all sessions it worked like charm !

这篇关于SignalR:有时谈判请求返回404错误(负载平衡)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆