I've managed to make it work, i've published the source on on GitHub https://github.com/jonathanlarouche/stackoverflow_q58027442
Prerequisites packages are : Asp.Net Web Application with the following Nuget packages :
Microsoft.AspNet.SignalR.Core 2.4.1
Microsoft.AspNet.SignalR.JS 2.4.1
Microsoft.AspNet.SignalR.SystemWeb 2.4.0
Microsoft.Owin.Security 2.1.0
Microsoft.Owin 4.0.0
web.config
<system.webServer>
node.
IMPORTANT Access-Control-Allow-Credentials
Is required when using Allow-Origin
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://localhost:20700" />
<add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Credentials" value="true"/>
</customHeaders>
</httpProtocol>
</system.webServer>
Startup.cs
Configuration file
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
In the Git solution, I've configured my Application to run under port 49611
, then i've published the Html page to a empty website running under port 20700
. SignalR requests now pass on port 49611 and CORS are working.
SignalR Client Html: (Working when running from http://localhost:20700/ or http://localhost:49611/)
<script type="text/javascript" src="/Scripts/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="/Scripts/jquery.signalR-2.4.1.min.js"></script>
<script type="text/javascript" src="http://localhost:49611/SignalR/hubs"></script>
<script type="text/javascript">
...
var ChatProxy;
function Connect() {
ChatServerUrl = "http://localhost:49611/";
var ChatUrl = ChatServerUrl + "signalr";
//This will hold the connection to the signalr hub
SignalrConnection = $.hubConnection(ChatUrl, {
useDefaultPath: false
});
ChatProxy = SignalrConnection.createHubProxy('ChatHub');
}
...
</script>
Download the Repo and try it
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…