SignalR was working while project was ASP.NET MVC3. Now i upgraded it to MVC5 (not so easy to do, I must tell you).
Then I noticed that signalR was not working. I went by the book, reinstalled SignalR to version 2.1.0, installed OWIN (must-have for v2+) and added startup class to project.
This is my startup.cs class, it sits at project root folder:
[assembly: OwinStartup(typeof(SISTEM.Startup))]
namespace SISTEM
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
I see no problem here, but maybe i am missing something...
Now here is snippet from the hub:
namespace SISTEM
{
public class PostingHub : Hub
{
public void Test(string hello)
{
Clients.All.hello(hello);
}
}
}
Then i reference generated proxys in view:
<script src="~/Scripts/jquery.signalR-2.1.0.min.js"></script>
<script src="~/signalr/hubs"></script>
I inspect it in fiddler and i can see that /signalr/hubs request is generating HTTP 404 not found.
Now, i wasn't lazy, i tried several things:
- Patch IIS for extensionless URLs - Shouldn't be a problem since I'm using win8
- Call RouteTable.Routes.MapHubs() before RegisterRoutes(RouteTable.Routes) - VS won't allow it. Gives me an error saying that's obsolete, use OWIN.
- Downloaded tool for generating javascript proxies (SignarR Utils), so i can manually reference them later. Tried to generate, went with no error, but generated js was empty. Tried several times. This was for me most interesting. Maybe for some reason proxy cannot be generated.
Any help would be appreciated.
UPDATE: Response from /signalr/hubs
<!DOCTYPE html>
<html>
<head>
<title>The resource cannot be found.</title>
<meta name="viewport" content="width=device-width" />
</head>
<body bgcolor="white">
<span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>The resource cannot be found.</i> </h2></span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
<br><br>
<b> Requested URL: </b>/signalr/hubs<br><br>
<hr width=100% size=1 color=silver>
<b>Version Information:</b> Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34212
</font>
</body>
[HttpException]: The controller for path '/signalr/hubs' was not found or does not implement IController.
at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Like Milos said, clearing temp folder will probably fix the problem. I have created a script for doing this which I call powerreset.cmd which should be run As Administrator:
The e:\empty folder, which will be the source, and using purge with robocopy should then clear the temp files.
You need to install Microsoft.Owin.Host.SystemWeb package in the project
Verify this link
If package is not installed then install the following package from the Package Manager Console (PMC):
UPDATE
It purely says that, its not able to detect your startup class, here are few more findings.
<add key="owin:AutomaticAppStartup" value="false" />
This should definitely work, if it doesn't then try creating signalR in sample project.
The SignalR js versions are supposed to be the same, but can be different. As a side effect you will find that error in browser console.
Sometimes the most evident things are left unnoticed.