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've struggled with this problem too and finally got to the point that was causing the problem. First of all, I have to say that with SignalR v2 calling
RouteTable.Routes.MapHubs();
inside Globalasax/Application_Start is obsolete and compiler even throws warning. Instead we now add a dedicated StartUp class with the following public method:All the configuration goes here.See the documentation for more info.
Now, after wasting many hours googling like a crazy I decided to throw an Exception inside the Configure method of the StartUp class I mentioned earlier. If no exception would be thrown then I'd understand that Owin does not even start. My guess was right. For some reason Owin was not starting or something was suppressing it. In my case it was this evil configuration setting in my web.config file:
I guess the name of the setting is pretty descriptive. Either remove this or change false to true.
For me the solution was to reinstall all the packages and restore all the dependecies.
Open nuget powershell and use this command.
Have you just installed IIS? In this case you might have to reinstall it:
may be because your hub class name is 'Test' and you are referring to 'test' in client side.
I had this 404 errors when i updated to Signalr 2.0 and deployed MVC project to the production server. Publishing project with the "delete all existing files prior to publish" option saved my problems.
hope this helps someone.
Perhaps worth mentioning: I'm running a Web Forms application that uses it's own manual routing. Since OWIN startup occurs after the routing tables have been set, the route for /signalr/hubs was never hit. I added a rule to ignore routes (IE: let web forms do the routing) on any path that starts with "/signalr". This solved my issue.