I am using SignalR(https://github.com/SignalR/SignalR) in my project. From here https://github.com/SignalR/SignalR/wiki/QuickStart-Hubs I got the idea how to use Hubs. But the "signalr/hubs" script is giving 404 error. Here is the url which becomes in View Source: http://localhost:50378/signalr/hubs giving 404 error
Here is my code: Hub:
public class Test:Hub { public void Start() { Caller.guid = Guid.NewGuid(); } public void TestMethod() { Clients.show("test", Caller.guid); } }
ASPX:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Title</title> <script src="../Scripts/jquery-1.6.4.min.js" type="text/javascript"></script> <script src="../Scripts/jquery.signalR.js" type="text/javascript"></script> <script src="<%= ResolveUrl("~/signalr/hubs") %>" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { var test = $.connection.test; $("#btnTest").click(function () { test.testMethod(); }); test.show = function (text, guid) { if (guid != test.guid) //notify all clients except the caller alert(text); }; $.connection.hub.start(function () { test.start(); }); }); </script> </head> <body> <form id="HtmlForm" runat="server"> <div> </div> </form> </body> </html>
Web.config:
<system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules runAllManagedModulesForAllRequests="true"> ....
Try call RouteTable.Routes.MapHubs() before RouteConfig.RegisterRoutes(RouteTable.Routes) in Global.asax.cs if you use MVC 4. It works for me.
RouteTable.Routes.MapHubs(); RouteConfig.RegisterRoutes(RouteTable.Routes);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With