40

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?

Stephen Hewlett
  • 2,415
  • 1
  • 18
  • 31
user685590
  • 2,464
  • 5
  • 30
  • 42

16 Answers16

30

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.

SimonF
  • 804
  • 1
  • 7
  • 14
  • 2
    Further info under the heading "404 not found error" here: http://www.asp.net/signalr/overview/troubleshooting-and-debugging/troubleshooting – cbp Aug 27 '13 at 05:10
  • 1
    Further - mapping hubs is no longer required in signalr 2.0 onwards (and in fact generates an error): http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/upgrading-signalr-1x-projects-to-20 – John Aug 07 '14 at 03:04
  • 1
    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! – Vishal Mar 07 '19 at 17:23
19

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

Chaitanya Gadkari
  • 2,669
  • 4
  • 30
  • 54
  • I think you are mistaken. There is no overload to `Application_Start` with `IAppBuilder` - I couldn't find in new ASP.NET version either – Simon_Weaver May 14 '15 at 04:58
  • 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 May 14 '15 at 05:58
  • @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 – Chaitanya Gadkari May 15 '15 at 10:17
13

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

chridam
  • 100,957
  • 23
  • 236
  • 235
  • 2
    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. – Master Yoda Apr 05 '16 at 17:36
  • 3
    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 – Simon Green Feb 06 '19 at 11:36
  • 4
    @chridam I don't know how to add a wildcard application map. Please tell us? – Su Llewellyn Feb 21 '19 at 22:50
  • I have tried this: 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 – mannyCalavera Jun 02 '19 at 16:14
  • 1
    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 – abhijat_saxena Jun 26 '20 at 18:37
8

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" />
Randy H.
  • 616
  • 5
  • 8
7

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>
    
Till Helge
  • 9,253
  • 2
  • 40
  • 56
Sobinscott
  • 521
  • 1
  • 10
  • 15
1

Make sure your site's AppPool targets the correct version of .NET Framework.

Sasha
  • 1,393
  • 16
  • 17
1

I might be a little late but hope it helps someone. Make sure this code run on start.

 Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    RouteTable.Routes.MapHubs()
 End Sub

Because I added a global.asax to my application and then a codebehind but put this in Global.asax file

 <%@ Application Language="VB" CodeBehind = "Global.asax.vb" %> /*This was wrong*/

So when i tried to run the application, the Application_Start in my global.asax did not initialize the hub. that's why it couldn't resolve signalr/hubs

fixed with this in my Global.asax

 <%@ Application Inherits="_Global" Language="VB" %>

and this in my Global.asax.vb:

 Public Class _Global
     Inherits System.Web.HttpApplication
Seichi
  • 273
  • 4
  • 11
  • 1
    Note - Mapping hubs is no longer required in SignalR version 2.0 onwards: http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/upgrading-signalr-1x-projects-to-20 – John Aug 07 '14 at 03:03
1

Check web.config, on segment AppSettings add

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

on Key must be white space on the end of the name key, like @Randy H.

cmyell11
  • 19
  • 3
0

I had no issues with routing in MVC3, but did get the path wrong. I would suggest you look at the source and see where the script is actually pointing, make sure it is resolving the application directory ok. And make sure you can physcially open the file with the correct path with your browser. E.g.

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

Can you open the file from a browser (replacing it with the correct subdirectory)?

If not, the hub might not be set up correct and it might point you in the right direction. Fiddler it.

The syntax I used was:

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

It might be the difference between Url.Content and ResolveUrl

Community
  • 1
  • 1
0

Similar problem I had on IIS version, I fixed it by restarting AppPool, restart web and its working now.

Usman
  • 1
0

there are potentially many causes of this 404 - a few common ones can be found by

  • Hit the url in the browser /signalr/hubs - if there is an error, you will see the full error come back.
  • check for duplication of HubName attribute if you have base class
  • ensure you have the correct version referenced in all projects (as to avoid binding errors)
JonathanC
  • 180
  • 7
0

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
Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128
0

I had the same problem, it was an asp.net project using signalR, it worked properly before I published but when I hosted it in IIS, it didn't.

After I inspected I realized the address /signalr/hubs is not correct, let me explain more, just do the following steps:

  1. Open up your web application in the browser (Using IIS), you see the interface you designed, yeah? now press ctrl+U or right click on the page an select View Page Source.

  2. You will see multiple links starting with <script> tag at the top of the page, find something like <script src="/signalr/hubs"></script> now click on it, if you are taken to the page which involves "404 - File or directory not found."you have some mistakes on defining address, find the true address and change the address in the address bar to observe the true result

In my case I needed to add my project name at the start of the address, so I had to change the address from:

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

to

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

in which MoveShape was my project name, now after pressing ctrl+U in the browser and following previously told steps, you click on the link and this time you see the true result, the page show codes starting with:

/*!
 * ASP.NET SignalR JavaScript Library v2.2.2
 * http://signalr.net/
 *
 * Copyright (c) .NET Foundation. All rights reserved.
 * Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 *
 */

yeah! that's it, it works properly, keep in mind that it had no problem when I was testing it using Visual studio but not after hosting in IIS, as others have recommended make a correct address by applying <%= ResolveUrl("~/") %> or other methods.

Muhammad Musavi
  • 2,512
  • 2
  • 22
  • 35
0

In my case, I lose some owin dependencies then I got the 404 NotFound error.

When I added following dependencies, I retrieve the proxy javascript file clearly from expecting URL. Like URL:1111/singlar/hubs

  • Microsoft.Owin
  • Microsoft.Owin.Core
  • Microsoft.Owin.Host.SystemWeb
  • Microsoft.Owin.Security
  • Owin

Hope the answer helps someone.

arslanaybars
  • 1,813
  • 2
  • 24
  • 29
0

In my startup.cs I changed the order from

app.UseWebApi(configuration);
app.MapSignalR();

to

app.MapSignalR();
app.UseWebApi(configuration);

And that fixed the issue.

It was working fine on localhost but the problem was that I have a custom global message handler that I'm using to display custom 404 messages on prod.

WebApiConfig.cs

config.MessageHandlers.Add( new WebApiCustomMessageHandler() );


public class WebApiCustomMessageHandler : DelegatingHandler
{
    protected override async Task<HttpResponseMessage> SendAsync(
        HttpRequestMessage request, CancellationToken cancellationToken )
    {

        HttpResponseMessage response = await base.SendAsync( request, cancellationToken );
        
        //...
        //... custom 404 handling
        //...

        return response;
    }
}

I was getting 404 for all requests to .../signalr

Fixing the order in startup.cs fixed the 404 issue in the global message handler.

0

What worked for me was that in the App_Start I created a new item and selected the OWIN Startup class.

enter image description here

Then I modified it to look like this: Adding the app.MapSignalR();

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

With This in the HTML

<script src="~/signalr/hubs"></script>
Timothy G.
  • 6,335
  • 7
  • 30
  • 46