当我切换到本地IIS时,遇到了同样的问题。通过“管理NuGet包”升级到signalR-2.2.0后,我读了这个readme.txt:
Please see http://go.microsoft.com/fwlink/?LinkId=272764 for more
information on using SignalR.
Upgrading from 1.x to 2.0
Please see http://go.microsoft.com/fwlink/?LinkId=320578 for more information on
how to upgrade your SignalR 1.x application to 2.0.
Mapping the Hubs connection
To enable SignalR in your application, create a class called Startup with the following:
using Microsoft.Owin;
using Owin;
using MyWebApplication;
namespace MyWebApplication {
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
Getting Started
See http://www.asp.net/signalr/overview/getting-started for more
information on how to get started.
Why does ~/signalr/hubs return 404 or Why do I get a JavaScript error:
'myhub is undefined'?
This issue is generally due to a missing or invalid script reference
to the auto-generated Hub JavaScript proxy at '~/signalr/hubs'. Please
make sure that the Hub route is registered before any other routes in
your application.
In ASP.NET MVC 4 you can do the following:
<script src="~/signalr/hubs"></script>
If you're writing an ASP.NET MVC 3 application, make sure that you are using Url.Content
for your script references:
<script src="@Url.Content("~/signalr/hubs")"></script>
If you're writing a regular ASP.NET application use ResolveClientUrl for your
script references or register them via the ScriptManager using a app
root relative path (starting with a '~/'):
<script src='<%: ResolveClientUrl("~/signalr/hubs") %>'></script>
If the above still doesn't work, you may have an issue with routing
and extensionless URLs. To fix this, ensure you have the latest
patches installed for IIS and ASP.NET.
由于我正在开发一个常规的ASP.NET应用程序,所以我必须更改以下内容:
<script src="/Scripts/jquery-1.10.2.min.js" ></script>
<script src="/Scripts/jquery.signalR-2.1.2.js"></script>
<script src="/signalr/hubs"></script>
转换为:
<script src='<%: ResolveClientUrl("~/Scripts/jquery-1.10.2.min.js") %'></script>
<script src='<%: ResolveClientUrl("~/Scripts/jquery.signalR-2.2.0.js") %>'></script>
<script src='<%: ResolveClientUrl("~/signalr/hubs") %>'></script>
之前我添加了一个名为 "Startup.SignalR.cs" 的类文件:
using Owin;
using Microsoft.AspNet.SignalR;
namespace WebApplication1
{
public partial class Startup
{
public void ConfigureSignalR(IAppBuilder app)
{
app.MapSignalR();
}
}
}
我的 Startup.cs 如下所示:
using Microsoft.Owin;
using Owin;
[assembly: OwinStartupAttribute(typeof(WebApplication1.Startup))]
namespace WebApplication1
{
public partial class Startup {
public void Configuration(IAppBuilder app) {
ConfigureSignalR(app);
ConfigureAuth(app);
}
}
}
现在在项目/属性中,我可以在调试/生产环境之间切换IIS Express和本地ISS。