Update:
Switching to IIS Express instead of the Visual Studio Development Server fixed the 501 error.
I’m trying to get SignalR working in my MVC4 application but I am running into a strange 501 error. I have followed a couple different tutorials but the result is always the same.
Any help would be appreciated.
I am using Visual Studio 2012 Pro RC and I installed SignalR 0.5.1 through the package manager console.
My code:
Layout
<script src="~/Scripts/jquery-1.7.2.min.js"></script>
<script src="~/Scripts/jquery.signalR-0.5.1.js" type="text/javascript"></script>
<script type="text/javascript" src="@Url.Content("~/signalr/hubs")"></script>
View
<script type="text/javascript">
$(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('<p>' + message + '</p>');
};
// Start the connection
$.connection.hub.start(function () {
// send our 'record' message to the hub
userlink.recordView(clientIp);
});
});
</script>
<input type="hidden" id="client-ip" value="@ViewBag.ClientIpAddress" />
<div id="view-updates"></div>
Hub Class
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);
}
}
Error I am receiving
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
Debugging in IIS instead of the Visual Studio Development Server fixes the issue, but I’m not sure why. Now I’m curious if anyone knows why it would work in one and not the other.