【问题标题】:SignalR website returns a 404 when deployed on IISSignalR 网站在 IIS 上部署时返回 404
【发布时间】:2014-06-18 18:49:29
【问题描述】:

我在 IIS 中部署 SignalR 1.3.1 .NET 4.0 WebForms 网站时遇到问题。该站点在 Visual Studio 2010 中运行良好,但在我使用已部署版本时返回“404 - 找不到文件或目录”。当客户端请求 ~/signalr/negotiate URL 获取negotiate.json 文件时,后台会出现 404。这是我的 IIS 的外观:

请注意,此处的 bin 文件夹仅包含我的 SignalR 1.3.1 .NET 4.0 WebForms 网站的 .dll 和 .pdb。它没有其他任何东西。

这是我的 Global.asax.cs 代码:

    protected void Application_Start(object sender, EventArgs e)
    {
        // Register the error handling pipeline module
        GlobalHost.HubPipeline.AddModule(new ErrorHandlingPipelineModule()); 

        // Register the default hubs route: ~/signalr/hubs
        RouteTable.Routes.MapHubs(new HubConfiguration { EnableCrossDomain = true });
    }

这是我的 SignalR Hub 代码:

public class EppafHub : Hub 
{
    /// <summary>
    /// Sends notifications for new vehicle launches.
    /// </summary>
    public void SendVehicleUpdates()
    {
        try
        {
            Clients.All.SyncVehicleUpdates();
        }
        catch (Exception ex)
        {

            throw;
        }
    }
}

这是我的 WPF 客户端代码:

ServicePointManager.DefaultConnectionLimit = 10;

// Establish a connection to the hub
var hubConnection = new HubConnection("http://MyServer:MyPort/");                
hubProxy = hubConnection.CreateHubProxy("EppafHub");

// Subscribe to the server events
hubProxy.On("SyncVehicleUpdates", new Action(() => SynchronizeVehicleUpdates()));

// Start the connection to the hub
hubConnection.Start().Wait();

我尝试启动 hubConnection 时收到 404 错误。我究竟做错了什么?有什么方法可以从 IIS 浏览集线器,看看问题出在部署还是代码上?我看到了类似的问题,但没有一个解决方案适合我。

我还直接在 IIS 服务器上安装了各种 SignalR nuget 包。

我还使用以下命令清除了 Asp.NET 缓存:

net stop w3svc
Remove-Item -Path "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\*" -Force -Recurse
net start w3svc

【问题讨论】:

  • 您是否将端口号更新为服务器上正在使用的端口号?你在服务器上使用端口吗?
  • @Erik 我已经为网站指定了一个固定端口。
  • 您是否打开了端口上的传入连接?在 Windows7 上,所有传入端口都被锁定。我用&gt; netsh http add urlacl url=http://192.168.1.42:58938/ user=everyone打开我正在使用的端口

标签: .net iis-7.5 signalr signalr-hub signalr.client


【解决方案1】:

检查以确保您的 IIS 服务器配置了the Extensionless URL handler

【讨论】:

  • 感谢@Drew 的回复。但更新不适用于我的服务器。
  • 好的,可以安装了,但是 IIS 中的 URL 处理程序设置是否正确?另外,您可以使用 web.config 的 和/或 部分更新问题吗?
【解决方案2】:

我遇到了同样的错误,将 SignalR 包添加到 IIS 机器解决了问题(IIS PC 与我的开发 PC 不同)。

  1. http://nuget.org/nuget.exe 下载nuget.exe。
  2. 启动 cmd shell(以管理员身份)并导航到您的 Web 目录。 (不确定这是必需的,但这是我为使其正常工作所做的一部分。)

    c:\inetpub\wwwroot>Nuget 安装 Microsoft.AspNet.SignalR

    c:\inetpub\wwwroot>Nuget 安装 Microsoft.Owin.Cors

  3. 在 cmd shell 中导航到

    C:\Windows\Microsoft.NET\Framework\v4.0.3031

  4. 运行 aspnet_regiis 命令:

    C:\Windows\Microsoft.NET\Framework\v4.0.3031>aspnet_regiis -i

  5. 由于我运行的是独立服务器,并且默认情况下 Windows7 已锁定所有传入端口,因此我使用以下方式打开端口:

    netsh http 添加 urlacl url=http://1xx.168.1.42:58938/user=everyone

  6. 我还在 VS 2013 中通过 Publishing to Disk 打包了我的 SignalR 客户端页面。Web.config 和 packages.config 文件可能是您所缺少的。

packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="jQuery" version="1.6.4" targetFramework="net45" />
  <package id="Microsoft.AspNet.SignalR.JS" version="2.1.2" targetFramework="net45" />
</packages>

web.config:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
</configuration>

您还可以尝试 SignalR 网站上的 MoveShape Demo 中更具包容性的 packages.config。

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="jQuery" version="1.10.2" targetFramework="net45" />
  <package id="jQuery.UI.Combined" version="1.10.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.Cors" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.SignalR" version="2.1.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.SignalR.Core" version="2.1.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.SignalR.JS" version="2.1.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.SignalR.SystemWeb" version="2.1.2" targetFramework="net45" />
  <package id="Microsoft.Owin" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Cors" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="2.0.1" targetFramework="net45" />
  <package id="Microsoft.Owin.Security" version="2.0.1" targetFramework="net45" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />
  <package id="Owin" version="1.0" targetFramework="net45" />
</packages>

【讨论】:

    【解决方案3】:

    事实证明,这是一个操作系统问题。在 Windows Server 2008 R2 中一切正常,但在 Windows Server 2008 中无法正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-22
      • 1970-01-01
      • 1970-01-01
      • 2011-08-06
      • 2012-06-28
      • 1970-01-01
      • 2011-11-05
      • 1970-01-01
      相关资源
      最近更新 更多