SignalR /signalr/hubs 404 Not Found

45,248

Solution 1

Try adding a wildcard application map to your server to help map the unknown extension in the script URL "~/signalr/hubs"

Solution 2

The order of route registration matters. I had this exact problem and fixed it by ensuring my global.asax.cs looked like this:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        RouteTable.Routes.MapHubs();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
    }
}

This was in a web site using SignalR, MVC and WebApi all together.

Solution 3

The reason of this 404 error is hubs are not mapped, previously it would have to be done as answered by SimonF. If you are using SignalR version 2 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();
        }
    }
}

referenace : http://www.asp.net/signalr/overview/releases/upgrading-signalr-1x-projects-to-20

Solution 4

If you are working on webforms, Please take the following steps

  1. In the webconfig:

    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true"/>
    
  2. In the page add reference to hub as

    <script src="/signalr/signalr/hubs"></script>
    

    instead of

    <script src="/signalr/hubs"></script>
    

Solution 5

I was able to fix the 404 on ~/signalr/hubs by changing the following appSetting in web.config to "true".

<add key="owin:AutomaticAppStartup" value="false" />
Share:
45,248
user685590
Author by

user685590

Updated on April 07, 2020

Comments

  • user685590
    user685590 about 4 years

    I am trying to deploy a SignalR site on IIS. Code all works fine in VS. But getting the 404 not found error trying to resolve signalr/hubs so far I have tried.

    1) Changing the Script ref to:

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

    2) Modifying Web.Config to include :

    <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <modules runAllManagedModulesForAllRequests="true">
        </modules>
    </system.webServer>
    

    3) Changing the invoke requests on IIS for UrlMappingsModule.

    4) added SignalR.Hosting.AspNet.dll to see if that would help anything.

    Not sure what else to try or check, any help or point in the right direction?

  • cbp
    cbp almost 11 years
    Further info under the heading "404 not found error" here: asp.net/signalr/overview/troubleshooting-and-debugging/…
  • shalke
    shalke over 10 years
    <script src="/signalr/signalr/hubs"></script> did work for me
  • John
    John almost 10 years
    Note - Mapping hubs is no longer required in SignalR version 2.0 onwards: asp.net/signalr/overview/signalr-20/…
  • John
    John almost 10 years
    Further - mapping hubs is no longer required in signalr 2.0 onwards (and in fact generates an error): asp.net/signalr/overview/signalr-20/…
  • nZeus
    nZeus over 9 years
    Do you know how to remove the second /signalr ?
  • aruno
    aruno about 9 years
    I think you are mistaken. There is no overload to Application_Start with IAppBuilder - I couldn't find in new ASP.NET version either
  • Chaitanya Gadkari
    Chaitanya Gadkari about 9 years
    from which class have you inherited your global.asax public class MvcApplication : System.Web.HttpApplication, I had used MvcApplication class as this and it worked for me. I did not continue with it, I used OwinStartup so I will try this again and update you on Application_Start. But I can assure 1st definitely works.
  • Chaitanya Gadkari
    Chaitanya Gadkari about 9 years
    @Simon_Weaver you are right,something is wrong. when i pass IAppBuilder in global.asax theres HTTP Error 403.14 - Forbidden error, it is going for directory browsing, I dont know why, there is no compile error. Edited the answer and removed second approach
  • Master Yoda
    Master Yoda about 8 years
    it works for me too! thanks so much Chridam. My problem was that the server was looking for the following "localhost/signalr/hubs" (determined using Chrome developer console). In reality the url is dynamic and so this would not pick up the js file needed.
  • Simon Green
    Simon Green over 5 years
    Hi, could you elaborate on how to add a wildcard application map, what details I need to add where etc, please? I have these symptoms now and would like to try out this answer
  • Su Llewellyn
    Su Llewellyn over 5 years
    @chridam I don't know how to add a wildcard application map. Please tell us?
  • Vishal
    Vishal over 5 years
    While this didn't work for me, it did point me in the right direction. In my case, I was missing the 'app.MapSignalR();' statement in the Startup.Configuration(IAppBuilder app) method. So, thank you!
  • mannyCalavera
    mannyCalavera about 5 years
    I have tried this: <script src="~/signalr/hubs"></script> but it did not work. What should i do? Can you guys help me please. @user685590 Can you update your answer with adding a wildcard application map to my server
  • abhijat_saxena
    abhijat_saxena about 4 years
    in my case - I was sending negotiate request to service1 and making sendNotification request from service2 - due to which the handshake was not happening properly, if you have multiple services, make sure you send negotiate request to all of them (as per the requirements) and add listeners to each one of them
  • Hagai Wild
    Hagai Wild about 3 years
    First time the (almost) least voted answer was the right one, thank you :)