简体   繁体   中英

SignalR /signalr/hubs 404 Not Found

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?

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.

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

尝试将通配符应用程序映射添加到您的服务器,以帮助映射脚本 URL“~/signalr/hubs”中的未知扩展名

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>

通过将 web.config 中的以下 appSetting 更改为“true”,我能够修复 ~/signalr/hubs 上的 404。

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

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.

确保您站点的 AppPool 以正确版本的 .NET Framework 为目标。

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

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

<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

我在 IIS 版本上遇到了类似的问题,我通过重新启动 AppPool、重新启动 web 和它的工作来修复它。

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)

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM