我正在研究一個應用程序,以使用SignalR在多個Web託管應用程序之間執行上下文同步。客戶端機器使用SignalR Owin主機實例化主機,並且應用程序通過JS代理的無代理版本連接到主機。我遇到的問題是「客戶端」應用程序託管在SignalR主機所不具備的SSL環境中(因爲它受限於本地計算機)。如果我嘗試從託管JavaScript客戶端的標準非SSL網站連接到Hub,則一切正常。只要我將客戶端加載到SSL網站,但是當我嘗試啓動連接時,我收到了「SignalR:協商請求期間的錯誤:未定義」。任何人都知道解決這個問題?SignalR:將SSL頁面上的JS客戶端連接到不使用SSL的SelfHost
主機:
public class SignalRHost : IDisposable
{
private IDisposable _webApp;
public SignalRHost(string url = "http://localhost:9000/")
{
_webApp = WebApplication.Start<Startup>(url);
}
public class Startup
{
public void Configuration(IAppBuilder app)
{
bool enableErrorDetail = false;
#if DEBUG
enableErrorDetail = true;
#endif
app.MapHubs(new HubConfiguration { EnableCrossDomain = true, EnableDetailedErrors = enableErrorDetail });
}
}
public void Dispose()
{
_webApp.Dispose();
}
}
JS客戶:
(function (ns_HubClient) {
ns_HubClient.connection;
ns_HubClient.proxy;
ns_HubClient.initialize = function() {
ns_HubClient.connection = $.hubConnection("http://localhost:9000");
ns_HubClient.proxy = ns_HubClient.connection.createHubProxy("fluencyHub");
ns_HubClient.proxy.on('addMessage', function (data) { ns_HubClient.processMessage(data); });
ns_HubClient.connection.start()
.done(function() {
alert("connection complete");
})
.fail(function (data) {
alert("connection start failed: " + data);
});
};
ns_HubClient.login = function (sUserName, sPassword, sDomain) {
var fluencyMessage = {
MessageId: "",
CallType: "Asynchronous",
Method: "Login",
Status: "",
Response: {},
Request: {
sUserName: sUserName,
sPassword: sPassword,
sDomain: sDomain
}
};
ns_HubClient.sendMessage(fluencyMessage);
};
ns_HubClient.writeLog = function (message, errorLevel) {
var logMessage = {
ErrorLevel: errorLevel,
Message: message
};
ns_HubClient.proxy.invoke("logMessage", logMessage);
};
ns_HubClient.processMessage = function (message) {
};
ns_HubClient.sendMessage = function (data) {
ns_HubClient.proxy.invoke("addMessage", data);
};
} (window.ns_HubClient = window.ns_HubClient || {}));