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 figured out how to use hubs. But the "signalr / hubs" script gives a 404 error. Here is the URL that becomes in View Source: http: // localhost: 50378 / signalr / hubs giving a 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"> .... 
+48
c # signalr
Jan 20 '12 at 12:37
source share
20 answers

You may not have added a link to SignalR.AspNet.dll . If I remember correctly, he was responsible for adding the route to /signalr/hubs .

+28
Jan 20 2018-12-12T00:
source share

Try calling RouteTable.Routes.MapHubs () before RouteConfig.RegisterRoutes (RouteTable.Routes) in Global.asax.cs if you are using MVC 4. This works for me.

  RouteTable.Routes.MapHubs(); RouteConfig.RegisterRoutes(RouteTable.Routes); 
+44
Mar 15 '13 at 1:02
source share

From SignalR 1.0.0 RC2 , there is a README in the package folder, which says that the route of the hubs must be set manually. :) Here is a fragment ...

 using System; using System.Web; using System.Web.Routing; namespace MyWebApplication { public class Global : System.Web.HttpApplication { public void Application_Start() { // Register the default hubs route: ~/signalr RouteTable.Routes.MapHubs(); } } } 
+14
Jan 23 '13 at 3:24
source share

In my case, the main reason for this 404 is that the hubs were not displayed correctly. RouteTable.Routes.MapHubs(); now out of date. To map hubs, you can create a launch class, as shown below.

 [assembly: OwinStartup(typeof(WebApplication1.Startup))] namespace WebApplication1 { public class Startup { public void Configuration(IAppBuilder app) { // Any connection or hub wire up and configuration should go here app.MapSignalR(); } } } 
+14
Feb 12 '15 at 11:45
source share

I also struggled with this problem and finally got to the point of causing this problem. First of all, I have to say that with SignalR v2 call RouteTable.Routes.MapHubs(); inside Globalasax / Application_Start is deprecated, and the compiler even warns. Instead, now add the highlighted StartUp class with the following public method:

 public void Configuration(IAppBuilder app) { app.MapSignalR(); } 

All configuration goes here. See the documentation for more information.

Now, having spent a lot of time searching googling like crazy, I decided to throw an Exception inside the Configure method of the StartUp class, which I mentioned earlier. If there were no exceptions, I would understand that Owin does not even start. My hunch was right. For some reason, Owen did not start, or something crushed him. In my case, it was an evil configuration parameter in my web.config file:

  <add key="owin:AutomaticAppStartup" value="false" /> 

I think the parameter name is pretty descriptive. Remove this or change false to true.

+12
Feb 11 '16 at 12:54 on
source share

Did you just install IIS? In this case, you will have to reinstall it:

 c:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i 
+4
Jan 08 '14 at 14:52
source share

You need to reference the JavaScript file with @Url.Content , assuming you are using ASP.NET MVC3

how

 <script src="@Url.Content("~/Scripts/jquery.signalR.min.js")" type="text/javascript"></script> 

See SignalR FAQ on GitHub

Edit: As Trevor De Kokekek noted in his comment, you do not need to add @Url.Content yourself if you are using MVC4 or later. Just add uri with ~/ . Check out this other SO question for more information.

+3
Jan 27 '12 at 10:32
source share

I had the same problem when running my code using the Visual Studio development server, and it worked when I changed my project settings to use the local IIS web server.

enter image description here

There was a flaw in this issue, which David Fowler commented on. The issue will be fixed in future releases, but now this is a workaround. At the moment, I can not find a link to the error.

+3
Dec 31 '13 at 18:16
source share

In short: in my case, I used R # (ReSharper) , right-clicked my project, which uses SignalR, and clicked Refactor => Delete Unused Links. Beware: this is shoot in the leg .: D

He removed the IMPORTANT DLL links from SignalR , which are used only at runtime, that is, they are not needed at compile time. Obviously, R # only checks compilation time dependencies.

Namely, these two links were missing:

  • Microsoft.AspNet.SignalR.SystemWeb
  • Microsoft.Owin.Host.SystemWeb (without this breakpoint in SignalR configuration method will not even be deleted).

NuGet packages are removed and then reinstalled. Fixed issue with /hubs 404.

+3
May 23 '14 at 16:00
source share

This is the complete answer from the SignalR wiki ( https://github.com/SignalR/SignalR/wiki/Faq ). He worked with me:

First, make sure you have a call to MapHubs () in Global.asax.

Please make sure the hub route is registered before any other routes in your application.

 RouteTable.Routes.MapHubs(); 

In ASP.NET MVC 4, you can do the following:

 <script type="text/javascript" src="~/signalr/hubs"></script> 

If you are writing an MVC 3 application, make sure you use Url.Content for the script links:

 <script type="text/javascript" src="@Url.Content("~/signalr/hubs")"></script> 

If you are writing a regular ASP.NET application, use ResolveClientUrl for the script links:

 <script type="text/javascript" src='<%= ResolveClientUrl("~/signalr/hubs") %>'></script> 

If the above still does not work, make sure you have RAMMFAR installed in the web.config file:

 <configuration> <system.webServer> <modules runAllManagedModulesForAllRequests="true"> </modules> </system.webServer> </configuration> 
+2
May 18 '14 at 15:59
source share

My project is an ASP.net 4.0 C # web application, the testing environment is Windows Server 2012.

I had the same problem with 1.0.0 RC2, I did what Michael offers, and it works. Thank.

@MatteKarla: when installing SignalR 1.0.0 RC2 from NuGet, the following links are added to the project:

  • Microsoft.AspNet.SignalR.Core
  • Microsoft.AspNet.SignalR.Owin
  • Microsoft.AspNet.SignalR.SystemWeb
  • Microsoft.Owin.Host.SystemWeb

I need to add Microsoft.CSharp manually or after compilation the following error will occur:

  • The predefined type "Microsoft.CSharp.RuntimeBinder.Binder" is not defined or imported
+1
Jan 24 '13 at 11:06
source share

I had these 404 errors when I upgraded to Signalr 2.0 and deployed the MVC project to a production server. The publishing project with the option "delete all existing files before publishing" saved my problems.

hope this helps someone.

+1
Jan 15 '14 at 6:46
source share

I also came across this problem in an ASP.NET 4.0 Web Forms application. He worked on development servers, but not in production environments. The decision that all requests / modules are executed in controlled mode does not suit us.

The solution we lowered (better for ASP.NET web forms) is as follows. Add the following section to Web.Config:

 <modules> <remove name="UrlRoutingModule-4.0" /> <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" /> <!-- any other modules you want to run in MVC eg FormsAuthentication, Roles etc. --> </modules> 
+1
Nov 23 '15 at 23:04
source share

Perhaps worth mentioning: I am launching a Web Forms application that uses its own manual routing. Since OWIN starts after the routing tables have been set up, the route for / signalr / hubs has never been reached. I added a rule to ignore routes (IE: let web forms perform routing) on ​​any path starting with "/ signalr". This solved my problem.

+1
May 19 '16 at 18:49
source share

I solved this problem by switching the .NET Framework Version application pool from version 2.0 to v4.0.

0
Mar 02 '16 at 8:31
source share

it may be because your hub class name is "Test" and you are referring to "test" on the client side.

0
Jul 29. '16 at 12:37
source share

you don't need the signalr / hubs file, it's just a simplified debugging and an easy way to call a function. see. What the generated proxy does for you , that's all. Everything will work without him.

0
Oct 07 '16 at 6:14
source share

For me, the solution was to reinstall all the packages and restore all the dependent ones.

Open the powershell command for nuget and use this command.

 Update-Package -Reinstall 
0
May 27 '17 at 9:46 a.m.
source share

adding app.MapSignalR(); the Startup class fixes the problem

0
Jun 23 '17 at 6:18
source share

Your problem is the server code. Just put app.UseSignalR() before app.UseSpaStaticFiles() in Startup.cs file

0
May 20 '19 at 8:22
source share



All Articles