MVC4 SignalR“signalr / hubs”501未实现错误

更新:切换到IIS Express而不是Visual Studio开发服务器修复了501错误。

我正在尝试让SignalR在我的MVC4应用程序中工作,但我遇到了一个奇怪的501错误。 我已经按照几个不同的教程,但结果总是一样的。

任何帮助,将不胜感激。

我正在使用Visual Studio 2012 Pro RC,我通过包管理器控制台安装了SignalR 0.5.1。

我的代码:

布局

   

视图

  $(function () { // capture the client IP var clientIp = $("#clientip").val(); // create the SignalR proxy var userlink = $.connection.userlink; // create our callback for the proxy userlink.updateViewCount = function (message) { $('#view-updates').html('

' + message + '

'); }; // Start the connection $.connection.hub.start(function () { // send our 'record' message to the hub userlink.recordView(clientIp); }); });

轮毂类

 public class UserLink : Hub { public void RecordView(string IpAddress) { QContext db = new QContext(); db.SiteVisits.Add(new SiteVisit { CreateDate = DateTime.Now, IpAddress = IpAddress }); db.SaveChanges(); int userCount = db.SiteVisits.Count(); string result = string.Format("There have been {0} visits to this page.", userCount); Clients.updateViewCount(result); } } 

我收到错误

 Failed to load resource: the server responded with a status of 501 (Not Implemented) http://localhost:58361/signalr/hubs Uncaught TypeError: Cannot set property 'updateViewCount' of undefined 

如果您尚未修复此问题,我认为您可能需要这样做:

 [HubName("userlink")] public class UserLink : Hub { // Implementation } 

顺便说一句,如果您的站点中有/ Signalr文件夹,那可能是导致501的原因。这会导致使用内置的Visual Studio Web服务器与~/signalr/hubs javascript引用冲突,但在IISExpress中工作正常。

在IIS而不是Visual Studio Development Server中进行调试可以解决问题,但我不确定原因。 现在我很好奇,如果有人知道为什么它会在一个而不是另一个工作。

对于原始问题没有必要有用,但是如果使用SignalR的0.5.x 并且安装了Visual Studio MVC工具,那么到达这里的其他人可能会有冲突。

VS工具和SignalR之间存在已知的冲突,很快就会修复。

只需删除
Microsoft ASP.NET MVC 3 & 4 - Visual Studio 2010 Tools

Control Panel\Programs\Programs and Features