服务器上的SignalR错误500 - asp.net
问题描述:
我有一个简单的聊天应用程序,在本地正常工作,但SignalR远程抛出内部服务器错误。服务器上的SignalR错误500 - asp.net
抛出错误的脚本是这样的:
http://mydomainname.com/signalr/negotiate?clientProtocol=1.5&connectionData ...
我已经看过了类似主题的其他答案,但没有人可以为我工作。这些是我引用的答案:SignalR Negotiate 404,SignalR Negotiate 404 on Subdomain。
下面是客户端代码:
$(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.
});
});
在导航到错误链接时,我得到一个加密的异常,如下所示:SignalR CryptographicException on AzureWebsites。有没有解决这个问题的方法?
我使用asp.net 4.5和SignalR 2.我已经尝试了很多东西,我不知道为什么内部服务器错误存在。任何帮助将不胜感激。
答
像@Pawel在上面的评论中说的,问题是http://mydomainname.com/signalr/negotiate
返回500错误:在这种情况下加密异常。
我设法通过加入Microsoft.AspNetCore.DataProtection.SystemWeb包来解决这个问题 - 如下所述:https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/compatibility/replacing-machinekey
你需要表现出异常的详细信息。 '协议错误:未知的传输.'因为服务器正在寻找传输,所以是正常的。导航到:'http:// mydomainname.com/signalr/negotiate',你应该得到500. – Pawel
@Pawel啊对不起,应该包括这一点。我得到一个加密异常如下所述:http://*.com/questions/15393684/signalr-cryptographicexception-on-azurewebsites。但在这种情况下不能确定正确的解决方案。 – GenAsis
您可能没有配置machineKey。 – Pawel