I am using SignalR(https://github.com/SignalR/SignalR) in my project. From here https://github.com/SignalR/SignalR/wiki/QuickStart-Hubs I got the idea how to use Hubs. But the "signalr/hubs" script is giving 404 error. Here is the url which becomes in View Source: http://localhost:50378/signalr/hubs giving 404 error
Here is my code: Hub:
public class Test:Hub
{
public void Start()
{
Caller.guid = Guid.NewGuid();
}
public void TestMethod()
{
Clients.show("test", Caller.guid);
}
}
ASPX:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Title</title>
<script src="../Scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="../Scripts/jquery.signalR.js" type="text/javascript"></script>
<script src="<%= ResolveUrl("~/signalr/hubs") %>" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var test = $.connection.test;
$("#btnTest").click(function () {
test.testMethod();
});
test.show = function (text, guid) {
if (guid != test.guid) //notify all clients except the caller
alert(text);
};
$.connection.hub.start(function () { test.start(); });
});
</script>
</head>
<body>
<form id="HtmlForm" runat="server">
<div>
</div>
</form>
</body>
</html>
Web.config:
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
....
I solved this issue by switching the application pool .NET Framework Version from v2.0 to v4.0.
This is a full answer from SignalR wiki (https://github.com/SignalR/SignalR/wiki/Faq). It worked with me:
First, make sure you have a call to MapHubs() in Global.asax.
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:
If you're writing an MVC 3 application, make sure that you are using Url.Content for your script references:
If you're writing a regular ASP.NET application use ResolveClientUrl for your script references:
If the above still doesn't work, make sure you have RAMMFAR set in your web.config:
Try call RouteTable.Routes.MapHubs() before RouteConfig.RegisterRoutes(RouteTable.Routes) in Global.asax.cs if you use MVC 4. It works for me.
you dont need the signalr/hubs file it is just to have easier debugging and straightforward way to call a function. see : See what the generated proxy does for you , that is all. Things will work without it.
I had this same problem when running my code using the Visual Studio development server and it worked when I changed my project settings to use IIS Local Web Server.
There was a defect raised against this issue which David Fowler commented on. The problem will be fixed in future releases but right now this is the workaround. I cant find the link to the bug at the moment.
From the SignalR 1.0.0 RC2 there is a README in the packages folder that says the Hubs route must be manually established. :) Here is a snippet...