SignalR negotiation with hub returns 200 but https://<servicename>.service.signalr.net returns 403

AkScript 5 Reputation points
2024-05-20T10:57:37.24+00:00

I'm using Signalr for websocket communication with my Angular app which uses "@microsoft/signalr" npm package, the connection is established and messages are passing through, however, in about 10% of the time, establishing the communication with the Signalr server fails, where the negotiation with my ASP.net core hub return 200 (the calls to srv/connect/notificationshub/negotiate?negotiateVersion=1) but than the call to https://<servicename>.service.signalr.net/client/negotiate?hub=notificationshub&asrs.op=%2Fnotificationshub&negotiateVersion=1&asrs_request_id=XXXXXX returns 403, what are the possible causes for this and how can I debug it?

collecting SignalR http logs in Log Analytics show nothing.

Azure SignalR Service
Azure SignalR Service
An Azure service that is used for adding real-time communications to web applications.
147 questions
{count} vote

1 answer

Sort by: Most helpful
  1. brtrach-MSFT 16,586 Reputation points Microsoft Employee
    2024-05-31T03:23:35.05+00:00

    @AkScript The 403 error that you are seeing when connecting to the SignalR service could be due to a number of reasons. Here are a few things that you can try to debug the issue:

    1. Check if there are any access policies that are blocking the client from accessing the SignalR service. You can check the access policies for your SignalR service in the Azure portal.
    2. Try pinging the SignalR service to see if there are any network issues. You can use the ping command to check if there are any network issues between your client and the SignalR service.
    3. Enable server-side logging for ASP.NET Core SignalR to get more information about the error. You can enable logging by adding the following code to your Startup.cs file:
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        // ...
    
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapHub<NotificationsHub>("/notificationshub");
        });
    
        // Add the following code to enable logging
        app.UseSignalR(routes =>
        {
            routes.MapHub<NotificationsHub>("/notificationshub")
                .RequireAuthorization();
        });
    }
    

    This will enable logging for the SignalR service and you can check the logs to see if there are any errors that are causing the 403 error.


Your answer

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