在IIS上部署时,SignalR网站返回404

时间:2014-06-18 18:49:30

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

我遇到在IIS中部署SignalR 1.3.1 .NET 4.0 WebForms网站的问题。该站点可以在Visual Studio 2010中正常工作,但返回的是“未找到的文件或目录”#39;当我使用部署版本时。当客户端请求negotiate.json文件的〜/ signalr / negotiate URL时,404就会出现在幕后。以下是我的IIS的外观:

enter image description here

请注意,这里的bin文件夹只有.dll和.pdb用于我的SignalR 1.3.1 .NET 4.0 WebForms网站。它没有别的东西。

这是我的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

3 个答案:

答案 0 :(得分:0)

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

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

    c:\ inetpub \ wwwroot&gt; Nuget安装Microsoft.AspNet.SignalR

    c:\ inetpub \ wwwroot&gt; Nuget安装Microsoft.Owin.Cors

  3. 在cmd shell中navaigate to

    C:\的Windows \ Microsoft.NET \框架\ v4.0.3031

  4. 运行aspnet_regiis命令:

    C:\ Windows \ Microsoft.NET \ Framework \ v4.0.3031&gt; aspnet_regiis -i

  5. 由于我运行独立服务器而Windows7默认锁定了所有传入端口,因此我使用以下命令打开端口:

      

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

  6. 我还通过在VS 2013中发布到磁盘来打包我的SignalR客户端页面.Web.config和packages.config文件可能是您缺少的。

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

答案 1 :(得分:0)

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

答案 2 :(得分:-1)

原来,这是一个操作系统问题。一切正常在Windows Server 2008 R2中运行,在Windows Server 2008中不起作用。