Share via

SignalR Chat Issue: I’m currently building chat system using SignalR in ASP.NET Core (.NET 9) for communication between a user and an admin. user message should be received instantly by the admin via SignalR

bright owusu 0 Reputation points
2026-03-30T10:58:27.9+00:00

Screenshot (660)

this is my browser where i want to inspect the error from

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


3 answers

Sort by: Most helpful
  1. Danny Nguyen (WICLOUD CORPORATION) 6,615 Reputation points Microsoft External Staff Moderator
    2026-03-31T06:48:33.51+00:00

    Hi bright owusu.

    To troubleshoot this, can you provide these details?

    1. How are you sending to the admin in your Hub? Clients.User(...), Clients.Group(...), or Clients.Client(...)?
    2. Are user/admin authenticated (cookies/Identity or JWT)?
    3. Can you paste: Program.cs (your MapHub), the Hub method that sends the message, and the JS HubConnectionBuilder() from the admin page?

    Also try checking:

    • In the browser open DevTools → Network → WS and check the *bsocket for your hub (e.g. /chathub). If it’s not 101 Switching Protocols or it keeps disconnecting, the admin isn’t actually connected.
    • Also check Network for /chathub/negotiate and its HTTP status/error.
    • Enable SignalR logging on the client:
    
    const connection = new signalR.HubConnectionBuilder()
    
      .withUrl("/chathub")
    
      .configureLogging(signalR.LogLevel.Information)
    
      .withAutomaticReconnect()
    
      .build();
    
    await connection.start();
    
    console.log("connected", connection.connectionId);
    
    

    Common issue might be that Clients.Client(x) expects a connectionId, not a userId. If you’re targeting the admin by user id, you usually want Clients.User(adminUserId) (and the user-id claim mapping must match).

    Please follow this guide regarding Authentication and authorization in ASP.NET Core SignalR https://learn.microsoft.com/aspnet/core/signalr/authn-and-authz?view=aspnetcore-9.0

    I hope that this helps with your problem. Let me know if anything comes up.

    If you found my response helpful or informative, I would greatly appreciate it if you could follow this guidance or provide feedback. Thank you. 


  2. Chanaka Thilakarathne 25 Reputation points
    2026-03-30T13:22:16.8933333+00:00

    Are you using the JavaScript client or .NET client for SignalR?

    If JS, can you check your version by running signalR.VERSION in browser console or checking your script URL?

    If .NET client, please check your package version in .csproj.

    Since the server is running on .NET 9, the client should ideally be version 9.x to avoid compatibility issues.

    0 comments No comments

  3. Q&A Assist
    2026-03-30T10:58:58.55+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To inspect and troubleshoot why the admin is not receiving the SignalR chat messages instantly, use the browser developer tools and SignalR logging features as follows.

    1. Open the browser dev tools on the admin and user pages
      • Press F12 to open the tools.
      • Use the Console tab to see JavaScript errors and SignalR log output.
      • Use the Network tab to inspect the SignalR connection and requests. Refresh the page (F5) so the connection handshake is captured from the start.
    2. Verify that the SignalR JavaScript client is loaded correctly
      • In the Console, check for 404 or script errors related to signalr.js or your chat script.
      • If signalr.js is in a different folder than expected, the reference will fail and appear as a 404 error in the console. Fix the <script src="..."></script> path and reload the page.
    3. Enable client-side SignalR logging
      • Configure logging when building the connection so that connection and messaging issues appear in the console:
         const connection = new signalR.HubConnectionBuilder()
             .withUrl("/chathub")
             .configureLogging(signalR.LogLevel.Information)
             .build();
      
      • This logs connection start, reconnects, and errors to the console. Use LogLevel.Trace for the most detailed output if needed.
    4. Wrap hub calls in try/catch and log errors
      • When sending a message from the user or admin, use invoke with error handling so any failure appears in the console:
         try {
             await connection.invoke("SendMessage", user, message);
         } catch (err) {
             console.error(err);
         }
      
      • If the hub method throws or the connection is not established, the error will be printed in the console.
    5. Confirm that the hub method and client handlers match
      • On the server hub (for example):
         public async Task SendMessage(string user, string message)
         {
             await Clients.All.SendAsync("ReceiveMessage", user, message);
         }
      
      • On the admin and user clients, register the handler before starting the connection:
         connection.on("ReceiveMessage", (user, message) => {
             // append message to chat UI
         });
      
      • The method name passed to SendAsync ("ReceiveMessage") must exactly match the name used in connection.on.
    6. Inspect the Network tab for the SignalR transport
      • Filter by WS (WebSocket) or look for /chathub (or your hub URL).
      • Verify that the connection is established and remains open.
      • If there is no connection or it closes immediately, check the console for related errors and the server logs.
    7. If using Azure SignalR Service
      • When calling hub methods from JavaScript with invoke, ensure the service is in Default mode; otherwise, client-to-hub method calls are not supported.

    By following these steps, any connection errors, JavaScript issues, or mismatches between hub and client methods will be visible in the browser console and network traces, allowing correction so that messages are delivered instantly between user and admin.


    References:

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.