Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR "signalr/hubs" giving 404 error

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"> .... 
like image 599
Rocky Singh Avatar asked Jan 20 '12 12:01

Rocky Singh


1 Answers

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); 
like image 58
Adamy Avatar answered Sep 20 '22 19:09

Adamy