问题
I'm trying to implement SignalR into my application. To start things of I just started with something very basic, but for some reason I'm getting an error the whole time. Pease could you have a look at my code and see where I'm doing something wrong. Thanks in advance.
Starup Code
using Microsoft.Owin;
using Owin;
[assembly: OwinStartupAttribute(typeof(CdvPortal.Startup))]
namespace CdvPortal
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
app.MapSignalR();
}
}
}
Hub Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
namespace CdvPortal.Hubs
{
public class ReservationsHub : Hub
{
public void NewReservations()
{
Clients.All.NewReservation("hey this works");
}
}
}
Client side code
<script src="~/Scripts/jquery-2.1.3.js"></script>
<script src="~/Scripts/jquery.signalR-2.2.0.js"></script>
@*<script src="~/Signalr/hubs"></script>*@
<script type="text/javascript">
(function () {
var connection = $.hubConnection();
var hub = connection.createHubProxy('reservationsHub')
hub.on('NewReservation', function (message) {
alert(message);
});
connection.start().done(function(){
hub.invoke('NewReservations')
});
}());
来源:https://stackoverflow.com/questions/29945911/client-doesnt-make-a-connection-to-the-signalr-server