0

List item

[2025-11-19T14:03:33.645Z] Error: Failed to start the transport 'WebSockets': Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.

this.hubConnection = new signalR.HubConnectionBuilder()
      .withUrl(
        `${environment.serviceUrl}/hubs/notifications?userId=${userId}&applicationId=${applicationId}`,
        {
          accessTokenFactory: () => {
            return this.authService.idToken;
          },
          
          transport: signalR.HttpTransportType.WebSockets
          
        }
      )
      .withAutomaticReconnect()
      .configureLogging(signalR.LogLevel.Debug)
      .build();

    this.hubConnection
      .start()
      .then(() => console.log('[SignalR] Connected'))
      .catch(err => console.error('[SignalR] Connection error:', err));
  }

I have already allowed cores

services.AddCors(o => o.AddPolicy("AllowCors", builder =>
            {
                builder.SetIsOriginAllowed(origin => true)
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials();
            }));

and same thing when i am doing with application which does not use any auth, it works.

4
  • 2
    have you used the auth header on your SignalR Hub? [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] Commented Nov 19 at 14:11
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Nov 19 at 16:07
  • @AHoughton, Yes i have used [Authorize] in my signalr hub and we are using authentication middleware to manage auth across the project. Commented Nov 20 at 11:05
  • @Community, So while creating websocket connection with signalr hub with the autherize project it is throwing error. but without authenticated project it is working well. Commented Nov 20 at 11:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.