简体   繁体   English

SignalR /signalr/hubs 404 未找到

[英]SignalR /signalr/hubs 404 Not Found

I am trying to deploy a SignalR site on IIS.我正在尝试在 IIS 上部署 SignalR 站点。 Code all works fine in VS.代码在 VS 中一切正常。 But getting the 404 not found error trying to resolve signalr/hubs so far I have tried.但是到目前为止我已经尝试过尝试解决信号器/集线器时出现404 not found错误。

1) Changing the Script ref to: 1)将脚本引用更改为:

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

2) Modifying Web.Config to include : 2) 修改 Web.Config 以包括:

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

3) Changing the invoke requests on IIS for UrlMappingsModule . 3) 更改 IIS 上UrlMappingsModule的调用请求。

4) added SignalR.Hosting.AspNet.dll to see if that would help anything. 4) 添加SignalR.Hosting.AspNet.dll以查看是否有帮助。

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:我遇到了这个确切的问题,并通过确保我的 global.asax.cs 看起来像这样来修复它:

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.这是在一个使用 SignalR、MVC 和 WebApi 的网站中。

The reason of this 404 error is hubs are not mapped, previously it would have to be done as answered by SimonF.这个 404 错误的原因是集线器没有映射,以前它必须按照 SimonF 的回答来完成。 If you are using SignalR version 2 RouteTable.Routes.MapHubs();如果您使用的是 SignalR 版本 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参考: 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检查 web.config,在段 AppSettings 上添加

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

on Key must be white space on the end of the name key, like @Randy H. on Key 必须是名称键末尾的空格,例如@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因为我在我的应用程序中添加了一个 global.asax,然后添加了一个代码隐藏,但是把它放在 Global.asax 文件中

 <%@ 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.因此,当我尝试运行该应用程序时, global.asax 中的 Application_Start 没有初始化集线器。 that's why it couldn't resolve signalr/hubs这就是它无法解析信号器/集线器的原因

fixed with this in my Global.asax在我的 Global.asax 中修复了这个

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

and this in my Global.asax.vb:这在我的 Global.asax.vb 中:

 Public Class _Global
     Inherits System.Web.HttpApplication

I had no issues with routing in MVC3, but did get the path wrong.我对 MVC3 中的路由没有任何问题,但确实弄错了路径。 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这可能是Url.Content 和 ResolveUrl之间的区别

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

there are potentially many causes of this 404 - a few common ones can be found by这个 404 的潜在原因有很多 - 可以通过以下方式找到一些常见的原因

  • Hit the url in the browser /signalr/hubs - if there is an error, you will see the full error come back.在浏览器中点击 url /signalr/hubs - 如果出现错误,您将看到完整的错误返回。
  • check for duplication of HubName attribute if you have base class如果您有基类,请检查 HubName 属性是否重复
  • 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.对我来说,解决方案是reinstall所有软件包并恢复所有依赖项。

Open nuget powershell and use this command.打开 nuget powershell并使用此命令。

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.我有同样的问题,它是一个使用 signalR 的 asp.net 项目,它在我发布之前正常工作,但是当我在 IIS 中托管它时,它没有。

After I inspected I realized the address /signalr/hubs is not correct, let me explain more, just do the following steps:我检查后发现地址/signalr/hubs不对,我再解释一下,只需执行以下步骤:

  1. Open up your web application in the browser (Using IIS), you see the interface you designed, yeah?在浏览器中打开您的 Web 应用程序(使用 IIS),您会看到您设计的界面,是吗? now press ctrl+U or right click on the page an select View Page Source.现在按ctrl+U或右键单击页面并选择查看页面源。

  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您将在页面顶部看到多个以<script>标签开头的链接,找到类似<script src="/signalr/hubs"></script>现在单击它,如果您被带到涉及的页面“404 - File or directory not found.”你在定义地址时有一些错误,找到真实地址并在地址栏中更改地址以观察真实结果

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:其中,MoveShape 是我的项目名称,现在在浏览器中按ctrl+U并按照之前的步骤操作后,您单击链接,这次您会看到真实的结果,页面显示的代码以以下开头:

/*!
 * 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.就是这样,它工作正常,请记住,当我使用 Visual Studio 测试它时没有问题,但在 IIS 中托管后没有问题,因为其他人建议通过应用<%= ResolveUrl("~/") %>创建正确的地址<%= ResolveUrl("~/") %>或其他方法。

In my case, I lose some owin dependencies then I got the 404 NotFound error.就我而言,我丢失了一些owin 依赖项,然后我收到了 404 NotFound错误。

When I added following dependencies, I retrieve the proxy javascript file clearly from expecting URL.当我添加以下依赖项时,我从预期的 URL 中清楚地检索了代理 javascript 文件。 Like URL:1111/singlar/hubs点赞网址:1111/singlar/hubs

  • Microsoft.Owin微软.Owin
  • Microsoft.Owin.Core微软.Owin.Core
  • Microsoft.Owin.Host.SystemWeb Microsoft.Owin.Host.SystemWeb
  • Microsoft.Owin.Security微软.Owin.Security
  • Owin欧文

Hope the answer helps someone.希望答案对某人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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