I'm trying to write a small SignalR project. When the project is set to run under IIS Express everything works as it should.
But when in Visual Studio project properties I switch to "Local IIS" and try to run, my page loads and does not connect to the SignalR Server.
I've checked with Fiddler and I found that while all script are loaded correctly relative to the path, the SignalR calls are made to the root of the website. So in fiddler I see something like this:
3 304 HTTP localhost /TestApp/Scripts/jquery-1.10.2.min.js 0 microsoftedgecp:11004
4 304 HTTP localhost /TestApp/Scripts/jquery.signalR-2.1.2.min.js 0 microsoftedgecp:11004
6 404 HTTP localhost /signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22testapphub%22%7D%5D&_=1440092162315 4,958 private text/html; charset=utf-8 microsoftedgecp:11004
As you can see, the SignalR is calling it's negotiate on /signalr
while the project is running under /TestApp/
How can I tell it to look at to correct location (relative) ?
Edit
This is my OwinStartup.cs
:
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
I have nothing defined in global.asax - should I?
I've found something that makes it work. It doesn't have to do with mapping in the OwinStartup (which after testing I found that is being called but not braked during debug).
After digging inside the js source file of SignalR I found this function the initializes a hub connection:
function hubConnection(url, options) {
/// <summary>Creates a new hub connection.</summary>
/// <param name="url" type="String">[Optional] The hub route url, defaults to "/signalr".</param>
/// <param name="options" type="Object">[Optional] Settings to use when creating the hubConnection.</param>
var settings = {
qs: null,
logging: false,
useDefaultPath: true
};
$.extend(settings, options);
if (!url || settings.useDefaultPath) {
url = (url || "") + "/signalr";
}
return new hubConnection.fn.init(url, settings);
}
As you can see, it takes a url parameter. So when I initialized my hub with the following code:
var connection = $.hubConnection('/TestApp/');
It now works. Now I just wrote a simple server side that checks weather it should initialize this parameter (if it's running in a sub-directory) and inject the value to the HTML page.