1
votes

I have Angular 6 app with aspnet/SignalR 1.0.3 support for .Net Core 2.1 (Microsoft.AspNetCore.SignalR 1.0.3 NuGet version). On connection, i am getting:

Error during WebSocket handshake: Unexpected response code: 500,

after that fallback to SSE also unsuccessful:

Error: Failed to start the transport 'ServerSentEvents': Error: Error occurred,

and at last, i am connected successfully with Long Polling.

Client code:

public createConnection() {
   const options: any = {
   transport: 0,
   accessTokenFactory: () => 'my token'
   };
   this._hubConnection = new HubConnectionBuilder()
  .withUrl('http://localhost:5000/chathub', options )
  .build();
}

When I set transport to 4 (long polling directly) - no errors. Question is why first two (best) transports does not work? Might it be that that latest client package version does not support .Net Core 2.1? Any idea how to avoid this behavior currently?

Thanks!

1
It sends the token as a url query and not in the Auth header. Make sure .net core authorisation is configured to extract the token from the query if it's not present in the header.Anton Toshik

1 Answers

2
votes

I think i figured out what was the issue. So, it was not anything wrong with the code, and worked perfectly with .NET client. I think the issue is that browsers doesn't like insecure ws protocol and because of that do the fallback. After upload to deployment which use https, wss protocol is used for communication and WebSocket work without any problems.

Hope that helps someone, cheers!