SignalR /signalr/hubs 404 Not Found

前端 未结 14 1309
时光说笑
时光说笑 2020-12-29 03:16

I am trying to deploy a SignalR site on IIS. Code all works fine in VS. But getting the 404 not found error trying to resolve signalr/hubs so far I have tri

相关标签:
14条回答
  • 2020-12-29 03:37

    If you are working on webforms, Please take the following steps

    1. In the webconfig:

      <validation validateIntegratedModeConfiguration="false" />
      <modules runAllManagedModulesForAllRequests="true"/>
      
    2. In the page add reference to hub as

      <script src="/signalr/signalr/hubs"></script>
      

      instead of

      <script src="/signalr/hubs"></script>
      
    0 讨论(0)
  • 2020-12-29 03:37

    I might be a little late but hope it helps someone. Make sure this code run on start.

     Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        RouteTable.Routes.MapHubs()
     End Sub
    

    Because I added a global.asax to my application and then a codebehind but put this in Global.asax file

     <%@ Application Language="VB" CodeBehind = "Global.asax.vb" %> /*This was wrong*/
    

    So when i tried to run the application, the Application_Start in my global.asax did not initialize the hub. that's why it couldn't resolve signalr/hubs

    fixed with this in my Global.asax

     <%@ Application Inherits="_Global" Language="VB" %>
    

    and this in my Global.asax.vb:

     Public Class _Global
         Inherits System.Web.HttpApplication
    
    0 讨论(0)
  • 2020-12-29 03:40

    I was able to fix the 404 on ~/signalr/hubs by changing the following appSetting in web.config to "true".

    <add key="owin:AutomaticAppStartup" value="false" />
    
    0 讨论(0)
  • 2020-12-29 03:40

    Make sure your site's AppPool targets the correct version of .NET Framework.

    0 讨论(0)
  • 2020-12-29 03:40

    I had no issues with routing in MVC3, but did get the path wrong. I would suggest you look at the source and see where the script is actually pointing, make sure it is resolving the application directory ok. And make sure you can physcially open the file with the correct path with your browser. E.g.

    <script src="/MyWebApp/signalr/hubs" type="text/javascript"></script>  
    

    Can you open the file from a browser (replacing it with the correct subdirectory)?

    If not, the hub might not be set up correct and it might point you in the right direction. Fiddler it.

    The syntax I used was:

    <script src="@Url.Content("~/signalr/hubs")" type="text/javascript"></script>  
    

    It might be the difference between Url.Content and ResolveUrl

    0 讨论(0)
  • 2020-12-29 03:44

    Check web.config, on segment AppSettings add

    <add key="owin:AutomaticAppStartup " value="false" />
    

    on Key must be white space on the end of the name key, like @Randy H.

    0 讨论(0)
提交回复
热议问题