c# – SignalR“启动请求期间出错.停止连接.“

内部错误
来自Fiddler:

The ConnectionId is in the incorrect format.

来自追踪:

SignalR.Transports.TransportHeartBeat Information: 0 : Connection 75e8d0ef-

64e2-463e-935d-a16759d948f1 is New.
SignalR.HubDispatcher Information: 0 : Failed to process connectionToken yhoTZnFsEnKUbd1/67eByQPhUb 3xkOsYMBXLLvp8nI29NnXrJE5zqHoFgLtA2VxOUJMAOreX6 7FGK4cGbal446Gs5YiV9F8MBduVMEXooL9fSeGpPHThvw56p6CzGX2yNmy7sy014gnak9l3BlZw==: System.FormatException: Invalid length for a Base-64 char array or string.
   at System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength)
   at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength)
   at System.Convert.FromBase64String(String s)
   at Microsoft.AspNet.SignalR.Infrastructure.DataProtectionProviderProtectedData.Unprotect(String protectedValue, String purpose)
   at Microsoft.AspNet.SignalR.PersistentConnection.TryGetConnectionId(HostContext context, String connectionToken, String& connectionId, String& message, Int32& statusCode)

这是来自Apache Cordava App(Visual Studio)的客户端调用,使用了ripple模拟器,我正在使用集线器,但有些在PersistentConnection失败了

http://localhost:4400/ripple/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=http%3A//localhost%3A52374/signalr/abort%3Ftransport%3DwebSockets%26clientProtocol%3D1.5%26connectionToken%3D6FHV%252BT%252F0WSoC3R8EEaseIe2481KxD24%252Fa31Toitf9kqUmIZw4jd87DgBnLWtVbLDZkZJA5gnEhQAUchyECh78738dIpuhqy1W4hAEVut%252F0gHr1Ou5bmpWbRi29sqRpwA4Y7Wc4WJPjYMpRIemgzP9w%253D%253D%26connectionData%3D%255B%257B%2522name%2522%253A%2522messagehub%2522%257D%255D HTTP/1.1
Host: localhost:4400

我的代码:

$.connection.hub.url = rooturl + "/signalr";
var chat = $.connection.messageHub;
$.connection.hub.start().done(function () {
                       $.connection.hub.disconnected(function () {
                           console.log('signlar connection abort');
                       });
                   }).fail(function (a) {
                       console.log('not connected' + a);
                   });

解决方法:

我使用Ripple仿真器时遇到了同样的错误,并设法通过执行以下操作来解决它:

1:在客户端上启用JSONP,更改以下内容

 $.connection.hub.start()

 $.connection.hub.start({ jsonp: true })

2.在启动期间在Configuration方法中启用服务器上的JSONP(在我的情况下为C#)

app.MapSignalR(new HubConfiguration
        {
            EnableJSONP = true,
            EnableJavaScriptProxies = true,
            EnableDetailedErrors = true
        });
上一篇:c# – 如何使用SignalR(单独的域)进行表单身份验证?


下一篇:c# – SignalR不调用jQuery函数