SignalR cannot read property client of undefined

前端 未结 10 2264
醉话见心
醉话见心 2020-12-13 08:42

I\'m trying to add SignalR to my project (ASPNET MVC 4). But I can\'t make it work.

In the below image you can see the error I\'m receiving.

相关标签:
10条回答
  • 2020-12-13 09:10

    Your hub classes must be defined as public. For example:

    class ChatHub : Hub
    

    should actually be

    public class ChatHub : Hub
    
    0 讨论(0)
  • 2020-12-13 09:11

    Make sure you add

    app.MapSignalR();
    

    inside startup.cs and Configuration method, like this:

     public partial class Startup
        {
            public void Configuration(IAppBuilder app)
            {
                app.MapSignalR();
            }
        }
    

    For Asp.net Core

    Add

    services.AddSignalR();
    

    in ConfigureServices methode in your startup.cs

    And add

    app.UseSignalR(routes =>
                {
                    routes.MapHub<ChatHub>("/chatHub");
                });
    

    in Configure methode in your startup.cs

    0 讨论(0)
  • 2020-12-13 09:14

    Making the Hub class "public" solved it for me.

    0 讨论(0)
  • 2020-12-13 09:19

    You should put SignalR and jQuery scripts, in correct order :

    <script src="/Scripts/jquery-1.6.4.min.js" ></script>
    
    <script src="/Scripts/jquery.signalR-1.1.4.js"></script>
    
    <script src="/signalr/hubs"></script> 
    
    0 讨论(0)
提交回复
热议问题