/signalr/hubs 404 not found after update to MVC5

10,637

Solution 1

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):

Install-Package Microsoft.Owin.Host.SystemWeb

UPDATE

It purely says that, its not able to detect your startup class, here are few more findings.

  • I believe this key is no more exist in config file <add key="owin:AutomaticAppStartup" value="false" />
  • Your application might be cached in temp folder, try deleting temporary files for your application.(Go to run > %TEMP% > CTRL + A > Delete)

This should definitely work, if it doesn't then try creating signalR in sample project.

Solution 2

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:

@echo off
@iisreset /stop
@robocopy e:\empty "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files" /PURGE
@robocopy e:\empty "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files" /PURGE
@iisreset /start

The e:\empty folder, which will be the source, and using purge with robocopy should then clear the temp files.

Solution 3

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.

Check the version of SignalR library in Scripts folder and the one referenced in your view.

  • ~/Scripts/jquery.signalR-2.1.0.min.js (SignalR tutorial);
  • jquery.signalR-2.2.1.min.js is installed into scripts folder (nuget installation: install-package Microsoft.AspNet.SignalR).

Sometimes the most evident things are left unnoticed.

Share:
10,637
Milos Mijatovic
Author by

Milos Mijatovic

Updated on June 16, 2022

Comments

  • Milos Mijatovic
    Milos Mijatovic almost 2 years

    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. &nbsp;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>&nbsp;Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34212
    
            </font>
    
    </body>
    

    [HttpException]: The controller for path &#39;/signalr/hubs&#39; 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)
    
    • Mox Shah
      Mox Shah over 9 years
      Does it hit this line " app.MapSignalR(); " ?
    • Milos Mijatovic
      Milos Mijatovic over 9 years
      No it doesn't. Good point. Should the line be hit on app start?
    • Mox Shah
      Mox Shah over 9 years
      Yes, otherwise it won't map signalR route, in order to make signalR working it must hit this line when your application start. Double check your config file, if you're missing something related to OWIN.
    • Milos Mijatovic
      Milos Mijatovic over 9 years
      I just had this one: <add key="owin:AutomaticAppStartup" value="false" /> but i removed it. What should be there, if that's not too much to ask?
    • Mox Shah
      Mox Shah over 9 years
      Check bellow answer or just install OWIN package from PMC if it's not.
    • Milos Mijatovic
      Milos Mijatovic over 9 years
      I will and i will let you know
    • Mox Shah
      Mox Shah over 9 years
      if it still not work then verify logs of SignalR requests in fiddler or in firebug network panel, and post it here, if it works then you can up vote and accept my answer :)
  • Milos Mijatovic
    Milos Mijatovic over 9 years
    no luck. I reinstalled Microsoft.Owin.Host.SystemWeb from version 2 to version 3 but nothing changed. I'll update my post for you to see response to /signalr/hubs request. app.MapSignalR(); still doesn't get hit.
  • Mox Shah
    Mox Shah over 9 years
  • Milos Mijatovic
    Milos Mijatovic over 9 years
    Clearing temp folder was 90% of solution. It started hitting app.MapSignalR(); after that. There was another dependecy issue after that but that was no real problem. Thanks for all your help.