I have an web app that I integrate SignalR for chat but I got error "Unable to get value of the property 'chatHub': object is null or undefined"
Below are the details...
in ASP.Net UserControl
<link rel="stylesheet" href="/Css/JQueryUI/themes/base/jquery.ui.all.css"> <link href="../Classes/SignalRChat/Css/ChatStyle.css" rel="stylesheet" /> <link href="../Classes/SignalRChat/Css/JQueryUI/themes/base/jquery.ui.all.css" rel="stylesheet" /> <link href="Css/gradients.css" rel="stylesheet" /> <link href="Css/MainCss.css" rel="stylesheet" /> <script src="Scripts/ui/jquery.ui.core.js"></script> <script src="Scripts/ui/jquery.ui.widget.js"></script> <script src="Scripts/ui/jquery.ui.mouse.js"></script> <script src="Scripts/ui/jquery.ui.draggable.js"></script> <script src="Scripts/ui/jquery.ui.resizable.js"></script> <script src="Scripts/jquery.signalR-2.0.2.min.js"></script> <script src="Scripts/jquery-1.8.2.min.js"></script> <script src="Scripts/jquery.signalR-2.0.2.min.js"></script> <script src="signalr/hubs"></script> in javascript
<script type="text/javascript"> $(function () { setScreen(false); // Declare a proxy to reference the hub. var chatHub = $.connection.chatHub; //THIS GETS THE ERROR in my startup
using Microsoft.Owin; using Owin; [assembly: OwinStartup(typeof(Akr.Web.Classes.SignalRChat.SignalRChatStartup))] namespace Akr.Web.Classes.SignalRChat { public class SignalRChatStartup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } } } in my hub
using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.AspNet.SignalR; namespace Akr.Web.Classes.SignalRChat { [CLSCompliant(false)] public class ChatHub : Hub { //... some methods... } } How can I make it work? Thanks
2 Answers
Make sure you only include the jquery.signalR-*.min.js script once after the jQuery script.
Also ensure that the server is responding with a script from "signalr/hubs". If you are getting a 404, perhaps you should be loading the script from "/signalr/hubs" instead (notice the non-relative path).
Lastly, ensure that your inline JS shows up after the jQuery/SignalR related scripts in your HTML.
Here are some more troubleshooting docs:
I think the solution could be the same as posted on Cannot read property 'chatHub' of undefined SignalR Hub, check you have the app.MapSignalR(); in Startup.cs class. See more here