SignalR跨域和IIS 7.5的路径集线器只能在本地服务器上,如何从外部访问呢? [英] SignalR cross domain and IIS 7.5 path to hub only works locally on the server, how to access it externally?
问题描述
我自托管我的C#的WinForms应用程序中的SignalR集线器服务器:
I am self hosting a SignalR Hubs server within my C# WinForms application:
string url = "http://localhost:8081/";
m_signalrServer = new Microsoft.AspNet.SignalR.Hosting.Self.Server(url);
// Map the default hub url (/signalr)
m_signalrServer.MapHubs();
// Start the SignalRserver
m_signalrServer.Start();
我的ASP.NET Web应用程序充当SignalR集线器JavaScript客户端:
My ASP.NET web application is acting as the SignalR Hubs JavaScript client:
<script type="text/javascript" src="/Scripts/jquery.signalR-1.0.0-alpha2.min.js"></script>
<script type="text/javascript" src="http://localhost:8081/signalr/hubs"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$.connection.hub.url = 'http://localhost:8081/signalr'
var myHub = $.connection.myHub;
$.connection.hub.error(function () {
console.log("Error!");
});
$.connection.hub.start()
.done(function () {
console.log("Connected!");
})
.fail(function () { console.log("Could not connect!"); });
});
</script>
这code正常工作时,我使用的是服务器的Web浏览器,因为它可以访问的http://本地主机:8081 / signalr /集线器
。
This code works properly when I am using the Server's web browser as it can access http://localhost:8081/signalr/hubs
.
但是,当您浏览网站通过外部的http:// SERVERIP
中,SignalR因为jQuery脚本正在寻找 HTTP失败//本地主机:8081 / signalr
(我相信它会在您的本地计算机上)
However, when you browse the site externally via http://serverip
, the SignalR fails because the JQuery script is looking for a http://localhost:8081/signalr
(which I believe it looks for on your local computer).
我已经改变了:
$.connection.hub.url = 'http://serverip:8081/signalr'
和我启用了8081网站的浏览,并可以通过 HTTP浏览到网站:// SERVERIP:8081
。然而,浏览到的http:// SERVERIP:8081 / SignalR /集线器
找不到枢纽文件可从的http://本地主机: 8081 / siganlr /集线器
。
and I enabled browsing of the website on 8081 and can browse to the website via http://serverip:8081
. However, browsing to http://serverip:8081/SignalR/Hubs
can not find the hub file that is available from http://localhost:8081/siganlr/hubs
.
此外,作为一个测试我启用SignalR通过App_Start文件夹中的ASP.NET Web应用程序中 - > RegisterHubs.cs文件: RouteTable.Routes.MapHubs();
Also, as a test I enabled SignalR within the ASP.NET web application via the App_Start folder -> RegisterHubs.cs file : RouteTable.Routes.MapHubs();
这样做使我能够浏览到的http:// SERVERIP:8081 / signalr /集线器
或的http:// SERVERIP / signalr /集线器
,我可以看到由ASP.NET网站所产生的枢纽。这不是我想要的,因为这不是我从我的C#WinForms应用程序托管中心。
Doing this allows me to browse to http://serverip:8081/signalr/hubs
or http://serverip/signalr/hubs
and I can see the hubs being generated by the ASP.NET website. This is not what I want because this is not the hubs I am hosting from my C# WinForms application.
再次,浏览到的http:// SERVERIP:8081 / signalr /集线器
没有找到signalr或上存在枢纽文件 HTTP ://本地主机:8081 / signalr /集线器
。有谁知道我怎样才能使这个文件提供给我的ASP.NET Web应用程序,这样我可以让SignalR外部工作?
Once again, browsing to http://serverip:8081/signalr/hubs
does not find signalr or the hubs file that exists on http://localhost:8081/signalr/hubs
. Does anyone know how I can make this file available to my ASP.NET web application so that I can make SignalR work externally?
编辑:我忘了提8081是服务器防火墙上打开
I forgot to mention 8081 is open on the server firewall.
推荐答案
将其更改为:
string url = "http://*:8081/";
m_signalrServer = new Microsoft.AspNet.SignalR.Hosting.Self.Server(url);
这篇关于SignalR跨域和IIS 7.5的路径集线器只能在本地服务器上,如何从外部访问呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!