SignalR "signalr/hubs" giving 404 error

C#asp.netSignalr

C# Problem Overview


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">
....

C# Solutions


Solution 1 - C#

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);

Solution 2 - C#

It could be that you haven't added a reference to SignalR.AspNet.dll. If I recall correctly it's responsible for adding the route to /signalr/hubs.

Solution 3 - C#

From the SignalR 1.0.0 RC2 there is a README in the packages folder that says the Hubs route must be manually established. :) Here is a snippet...

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();
        }
    }
}

Solution 4 - C#

In my case, the main reason of this 404 is hubs were not properly mapped. RouteTable.Routes.MapHubs(); is now obsolete. For mapping hubs you can create a startup class as 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();
        }
    }
}

Solution 5 - C#

I've struggled with this problem too and finally got to the point that was causing the problem. First of all, I have to say that with SignalR v2 calling RouteTable.Routes.MapHubs(); inside Globalasax/Application_Start is obsolete and compiler even throws warning. Instead we now add a dedicated StartUp class with the following public method:

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

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

Now, after wasting many hours googling like a crazy I decided to throw an Exception inside the Configure method of the StartUp class I mentioned earlier. If no exception would be thrown then I'd understand that Owin does not even start. My guess was right. For some reason Owin was not starting or something was suppressing it. In my case it was this evil configuration setting in my web.config file:

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

I guess the name of the setting is pretty descriptive. Either remove this or change false to true.

Solution 6 - C#

I had this same problem when running my code using the Visual Studio development server and it worked when I changed my project settings to use IIS Local Web Server.

enter image description here

There was a defect raised against this issue which David Fowler commented on. The problem will be fixed in future releases but right now this is the workaround. I cant find the link to the bug at the moment.

Solution 7 - C#

Have you just installed IIS? In this case you might have to reinstall it:

c:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i

Solution 8 - C#

Long story short: in my case I used R# (ReSharper), right clicked my project that uses SignalR and clicked Refactor => Remove Unused References. Watch out: this is a shoot in the foot. :D

It removed IMPORTANT DLL references from SignalR that are used only during runtime, that is, they are not necessary during compile time. Obviously R# only checks for compile time dependencies.

Namely these 2 references were missing:

  1. Microsoft.AspNet.SignalR.SystemWeb
  2. Microsoft.Owin.Host.SystemWeb (without this one a breakpoint in SignalR OWIN Configuration method won't even be hit).

Removed the NuGet packages and then reinstalled them. Fixed the /hubs 404 issue.

Solution 9 - C#

You need to reference the JavaScript file with @Url.Content, assuming ou're using ASP.NET MVC3

Like:

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

See the SignalR FAQ on GitHub

Edit: As Trevor De Koekkoek mentioned in their comment, you do not need to add @Url.Content yourself if you're using MVC4 or later. Simply prepending the uri with ~/ suffices. For more information, check out this other SO question.

Solution 10 - C#

This is a full answer from SignalR wiki (https://github.com/SignalR/SignalR/wiki/Faq). It worked with me:

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

Please make sure that 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're writing an MVC 3 application, make sure that you are using Url.Content for your script references:

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

If you're writing a regular ASP.NET application use ResolveClientUrl for your script references:

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

If the above still doesn't work, make sure you have RAMMFAR set in your web.config:

<configuration>
   <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
        </modules>
    </system.webServer>
</configuration>

Solution 11 - C#

My project is ASP.net 4.0 C# Web App, testing environment is Windows Server 2012.

I had the same issue with 1.0.0 RC2, I did what Michael suggests and it works. Thanks.

@MatteKarla: When install SignalR 1.0.0 RC2 by NuGet, following references are added to project:

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

I have to add Microsoft.CSharp manually or following error will occurred during compile:

  • Predefined type 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported

Solution 12 - C#

I had this 404 errors when i updated to Signalr 2.0 and deployed MVC project to the production server. Publishing project with the "delete all existing files prior to publish" option saved my problems.

hope this helps someone.

Solution 13 - C#

I too came across this same issue on an ASP.NET 4.0 Web Forms application. It worked on development servers, but not in production environments. The solution of ensuring all requests/modules run in managed mode wasn't acceptable for us.

The solution we went down (better for ASP.NET Web Forms) is the following. 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 e.g. FormsAuthentication, Roles etc. -->
</modules>

Solution 14 - C#

Perhaps worth mentioning: I'm running a Web Forms application that uses it's own manual routing. Since OWIN startup occurs after the routing tables have been set, the route for /signalr/hubs was never hit. I added a rule to ignore routes (IE: let web forms do the routing) on any path that starts with "/signalr". This solved my issue.

Solution 15 - C#

I solved this issue by switching the application pool .NET Framework Version from v2.0 to v4.0.

Solution 16 - C#

may be because your hub class name is 'Test' and you are referring to 'test' in client side.

Solution 17 - C#

you dont need the signalr/hubs file it is just to have easier debugging and straightforward way to call a function. see : See what the generated proxy does for you , that is all. Things will work without it.

Solution 18 - C#

For me the solution was to reinstall all the packages and restore all the dependecies.

Open nuget powershell and use this command.

Update-Package -Reinstall

Solution 19 - C#

adding app.MapSignalR(); in Startup class resolves the issue

Solution 20 - C#

In my case (signalr was added to existing, big mvc project) the reason of not firing OWIN Startup.Configruation() were missing "dependedntAssembly" and wrong "targetFramwerork" version in web.config.

I have created simple signalR project from scratch and compared web.config files. What has helped us was:

  1. Correction from 4.5 to 4.5.2 in
    <httpRuntime targetFramework="4.5" ... > 
    <compilation debug="true" targetFramework="4.5" ... >
  1. adding dependent assemblies:
<dependentAssembly> 
	<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
	<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> 
</dependentAssembly>
<dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
	<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> 
</dependentAssembly>

Solution 21 - C#

I was getting that exception because my url hosting was wrong. I wrote "/chathub" but in my endpoint It said "/chat"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRocky SinghView Question on Stackoverflow
Solution 1 - C#AdamyView Answer on Stackoverflow
Solution 2 - C#MatteKarlaView Answer on Stackoverflow
Solution 3 - C#Michael RView Answer on Stackoverflow
Solution 4 - C#Chaitanya GadkariView Answer on Stackoverflow
Solution 5 - C#Mikayil AbdullayevView Answer on Stackoverflow
Solution 6 - C#SecretDeveloperView Answer on Stackoverflow
Solution 7 - C#DunkenView Answer on Stackoverflow
Solution 8 - C#Leniel MaccaferriView Answer on Stackoverflow
Solution 9 - C#thomauxView Answer on Stackoverflow
Solution 10 - C#SaadView Answer on Stackoverflow
Solution 11 - C#VinixView Answer on Stackoverflow
Solution 12 - C#arun.mView Answer on Stackoverflow
Solution 13 - C#DonView Answer on Stackoverflow
Solution 14 - C#HowardView Answer on Stackoverflow
Solution 15 - C#MichaelAttardView Answer on Stackoverflow
Solution 16 - C#Ujjwal Kumar GuptaView Answer on Stackoverflow
Solution 17 - C#sajuView Answer on Stackoverflow
Solution 18 - C#Mihai Alexandru-IonutView Answer on Stackoverflow
Solution 19 - C#Kamran QadirView Answer on Stackoverflow
Solution 20 - C#Łukasz SokołowskiView Answer on Stackoverflow
Solution 21 - C#jan4coView Answer on Stackoverflow