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...
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.
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