SignalR协商404 [英] SignalR Negotiate 404
问题描述
我正在使用SignalR 2.0.在VS 2012上本地运行时,一切正常.但是,当我在IIS上发布站点时,它会中断.该站点已加载,但其中一个脚本返回404 Not Found.该脚本类似于.
I am using SignalR 2.0. Everything works fine when running locally on my VS 2012. But when I publish the site on IIS, it breaks. The site loads but one of the scripts returns 404 Not Found. The script is something like.
此路径确实不存在.正确的路径应为:
This path doesn't exist indeed. The correct path should be:
https://example.com /private /signalr/negotiate?xxx >
https://example.com/private/signalr/negotiate?xxx
请注意以粗体显示的部分.
Note the part in bold.
在网站内( https://example.com/)我有另一个应用程序(
Inside the WebSite (https://example.com/) I have another Application (https://example.com/private/). This one is using SignalR.
这似乎是SignalR中的错误,因为可以从我的私人站点访问信号器/集线器路径.
This seems like a bug in SignalR since the signalr/hubs path is accessible from my private site.
推荐答案
我遇到了类似的问题. 这是用于配置的文档/signalr URL .
I had a similar problem. Here is the documentation for configuring the /signalr URL.
但是,我的解决方案与文档不同.
我没有更改标准的app.MapSignalR()
,而是将客户端代码更改为使用/MyApp/signalr
.这是代码,其中"MyApp"是我的Web应用程序的虚拟目录.
However, my solution differed from the docs.
Instead of changing the standard app.MapSignalR()
, I changed my client code to use /MyApp/signalr
. Here is the code where "MyApp" is the virtual directory of my web application.
var connection = $.hubConnection('/MyApp/signalr', {useDefaultPath: false});
var changesHub = connection.createHubProxy('changesHub');
changesHub.on('userCountChanged', function (count) {
$('#user-count').text(count);
});
connection.start().done(function () {
console.log('Hub has started');
changesHub.invoke('subscribeToChanges', user.id);
});
我尝试了另一种方法(将MapSignalR更改为/signalr路径),但这没有用,并且协商仍路由到/MyApp/signalr/negotiate.
I tried the other way around (change the MapSignalR to the /signalr path) but this did not work and the negotiation was still routed to /MyApp/signalr/negotiate.
这篇关于SignalR协商404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!