I
I
Islam Dortkuliev2019-05-03 09:11:48
ASP.NET
Islam Dortkuliev, 2019-05-03 09:11:48

ASP.NET SignalR. Error connecting to WebSocket. What could be the problem?

Hello. Maybe I am asking a lot of questions. I'm trying to connect to SignalR Hub from a SPA application.

this.hubConnection = new HubConnectionBuilder()
    .withUrl('http://localhost:*****/testhub')
    .configureLogging(LogLevel.Information)
    .build()

Error: Error: Failed to complete negotiation with the server: SyntaxError: Unexpected token < in JSON at position 0
Tried like this:
this.hubConnection = new HubConnectionBuilder()
    .withUrl('http://localhost:*****/testhub', {
      skipNegotiation: true,
      transport: HttpTransportType.WebSockets
    })
    .configureLogging(LogLevel.Information)
    .build()

Error:
WebSocket connection to 'ws://localhost:50523/testhub' failed: Error during WebSocket handshake: Unexpected response code: 200
I enabled the use of web sockets in Startup.cs. I tried to change the version of SignalR in the client side, the error does not disappear. In multi-page applications, everything is fine.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Islam Dortkuliev, 2019-05-03
@KiberionCoder

Problem solved. In Startup.cs I moved the UseSignalR line above UseMvc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question