7

Trying to get signalr up and running. I keep getting 2 errors back from the server:

  1. GET negotitate url returns 500 Internal Server Error
  2. XMLHttpRequest cannot load http://localhost:10772//signalr/negotiate ... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 500.

Screenshot provided.

Any ideas?

enter image description here]1

hannes neukermans
  • 12,017
  • 7
  • 37
  • 56

3 Answers3

2

OK, found it out myself. Spelling error. The name of the hub mentioned was incorrect.

changed:
var proxy = this.connection.createHubProxy('chattAppHub');

to:
var proxy = this.connection.createHubProxy('ChatAppHub');

In the backend:
[HubName("ChatAppHub")]
public class ChatAppHub : Hub ...

inside startup.cs
var hubConfiguration = new HubConfiguration(); hubConfiguration.EnableDetailedErrors = true; appBuilder.MapSignalR(hubConfiguration); appBuilder.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

hannes neukermans
  • 12,017
  • 7
  • 37
  • 56
0

This fixed it for me:

C# Startup.cs tweak:

app.MapSignalR(new HubConfiguration{EnableJSONP = true});

JavaScript tweak:

connection.start({ jsonp: true })

We need JSONP anyways so for us it was a good solution.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Jesse Hufstetler
  • 583
  • 7
  • 13
0

I had the same problem, it is all about CORS. You should add Host URL in CORS config in Sturtup.cs, Have look at:

https://stackoverflow.com/a/59891997/854405

Mehdi Payervand
  • 251
  • 3
  • 11