I connect to the server with angular like this:
this._hubConnection = new signalR.HubConnectionBuilder()
.withUrl(location.protocol + '//localhost:5000/notify')
.configureLogging(signalR.LogLevel.Information)
.build();
There is no problem with the code or the host. The request works.
But then the library makes an additional call to:
http://localhost:5000/notify/negotiate
Then I get this error:
HTTP ERROR 405
The full error in the client is:
Failed to load http://localhost:5000/notify/negotiate: Response to
preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
I don't have cors issues in the site apart from the aforementioned request.
I have this configured in the startup.cs.
app.UseCors(builder =>
builder.WithOrigins("http://localhost:4200").AllowAnyMethod
().AllowAnyHeader().AllowAnyOrigin());
The code works for all the site.
Why that sudden cors error if the rest of the requests work?
I can suggest you to configure directly web.config file of your webapp adding following lines of code (it works on IIS, not sure for IIS Express):