1

I have a simple chat application that works fine locally, but the SignalR throws an internal server error remotely.

The script that throws the error looks like this:

http://mydomainname.com/signalr/negotiate?clientProtocol=1.5&connectionData...

Here is the log: enter image description here

I have looked at other answers on a similar topic but none seem to work for me. These are the answers I referenced: SignalR Negotiate 404, SignalR Negotiate 404 on Subdomain.

Here is the client code:

$(function () {
                // Reference the auto-generated proxy for the hub.
                $.connection.hub.url = 'http://mydomainname.com/signalr';
                $.connection.hub.logging = true;

                var chat = $.connection.chatHub;

                var name = '<%= username%>'
                // Create a function that the hub can call back to display messages.
                chat.client.addNewMessageToPage = function (name, message) {
                    // Add the message to the page.
                    bootbox.alert({
                        message: "<b>" + name + "</b>: " + message,
                    });
                };

                chat.client.sendMessage = function (name, message) {
                    // Add the message to the page.
                    $('#discussion').append('<li><strong>' + htmlEncode(name)
                       + '</strong>: ' + $('#message').val() + '</li>');
                };
                // Start the connection.
                $.connection.hub.start().done(function () {
                   // code to append message omitted.
                });
});

On navigating to the error link I get a Cryptographic Exception as shown here: SignalR CryptographicException on AzureWebsites. Is there a solution to this problem?

I'm using asp.net 4.5 and SignalR 2. I have tried lots of things and I'm not sure why the internal server error exists. Any help will be greatly appreciated.

Community
  • 1
  • 1
IRSAgent
  • 319
  • 1
  • 3
  • 12
  • You need to show exception details. `Protocol error: Unknown transport.` is normal since the server is looking for the transport. Navigate to: `http://mydomainname.com/signalr/negotiate` and you should get 500. – Pawel Feb 21 '17 at 23:21
  • @Pawel ah yes sorry, should've included that. I get a Cryptographic Exception as described here: http://stackoverflow.com/questions/15393684/signalr-cryptographicexception-on-azurewebsites. But not sure of the correct solution in this case. – IRSAgent Feb 21 '17 at 23:41
  • 1
    You probably don't have the machineKey configured. – Pawel Feb 21 '17 at 23:53
  • @Pawel thanks, it seems that it was something related to the machineKey. I just added the Microsoft.AspNetCore.DataProtection.SystemWeb package and it's good now. – IRSAgent Feb 22 '17 at 02:06
  • This does not seem to be right. Microsoft.AspNetCore.DataProtection.SystemWeb is an ASP.NET Core package and SignalR 2 is not Core. – Pawel Feb 22 '17 at 02:35
  • Good point, that did however solve my issue. Now that you point it out, not sure why that worked. – IRSAgent Feb 22 '17 at 02:44

1 Answers1

0

Like @Pawel said in the comment above, the problem was with the http://mydomainname.com/signalr/negotiate returning a 500 error: Cryptographic Exception in this case.

I managed to solve this by adding the Microsoft.AspNetCore.DataProtection.SystemWeb package - as described here: https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/compatibility/replacing-machinekey

IRSAgent
  • 319
  • 1
  • 3
  • 12