【发布时间】: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 上,所有传入端口都被锁定。我用
> netsh http add urlacl url=http://192.168.1.42:58938/ user=everyone打开我正在使用的端口
标签: .net iis-7.5 signalr signalr-hub signalr.client