How do I get a SignalR hub API connection to work cross-domain? - asp.net-mvc-5

I am connecting my Signalr hub Api in different mvc5 application with javascript signalr client its perfectly works on localhost when i publish my SignalrHubAPI its gives an error negotiate 403

Related

Error: Failed to start the transport 'LongPolling': Error: No Connection with that ID: Status code '404'

I have created a signalr selfhosted webapp service that connects to on prem signalr service using hybrid connection. This self hosted service then broadcast the changes to front end and back to on prem signalR. The self hosted service is fronted by a front door.
Everything works fine locally with long polling (front door doesn't support websockets), but doesn't work when deployed in Azure. Error: Failed to start the transport 'LongPolling': Error: No Connection with that ID: Status code '404'
Anything i am missing?
Enabled the clientAffinity on the app service and that did the magic. Also on Azure front door removed the host header on the backend

NullReferenceException from Azure SignalR Hub during WebSocket handshake

I'm trying to use the Azure SignalR service. I've already got SignalR working locally, but when I upgrade it to use the Azure service I see the following:
Client connects to (local, .NET) hub server configured to use Azure SignalR service and is 'redirected' to our hosted SignalR service on Azure.
Client connects with https to SignalR service at https://blabla.service.signalr.net and (after a preflight request) gets a 200 response with a json payload containing list of available transports etc.
Client opens a WebSocket to the wss://blabla.service.signalr.net host. First upstream message is {"protocol":"json","version":1}.
Server responds immediately with the following response:
{"error":"An unexpected error occurred during connection handshake. NullReferenceException: Object reference not set to an instance of an object."}
What's puzzling me is that
There is no code of ours running in the SignalR service which could be causing this.
Our Hub server shows no errors related to calls from the SignalR service.
I've successfully run a chat hub on the same SignalR service using the same hub server.
How do I debug this? I can't see any activity logs on the Azure portal, and nothing is showing up locally on the hub server.
I managed to find the source of the problem by adding debugging entries to my app settings.json as follows:
"Microsoft.AspNetCore.SignalR": "Debug",
"Microsoft.AspNetCore.Http.Connections": "Debug"
This revealed that the problem was related to a call made from the SignalR service to my local hub server (via a WebSocket connection presumably)

Connecting Application to Azure SignalR Service

I'm trying to connect my application to Azure SignalR Service. The application works fine using SignalR locally or even using Azure App Services.
services.AddSignalR();
The code above is what I had and everything works.
services.AddSignalR().AddAzureSignalR(Configuration.GetValue<string>("SignalRConnectionString"));
This is the change to be able to use Azure SignalR Service.
In the logs, I can see that the request is being forwarded to the Azure End Point.
I keep getting this error.
failed: HTTP Authentication failed; no valid credentials available

Azure SignalR negotiate fails

I have angular project hosted on www.allbaskets.com
An Api app in asp.net core 3.1 on messenger.allbaskets.com with SignalR Hub called messengerhub registered as Messenger.
The hub is using Azure SignalR.
I've adde CORS https://www.allbaskets.com , https://allbaskets.com to the APi
and https://www.allbaskets.com , https://allbaskets.com , messenger.allbaskets.com to CORS in Azure SignalR
The APi and angular app is hosted on Azure app service.
On connecting www.allbaskets.on the browser i constantly see a negotiate failed with the url as
https://messenger.allbaskets.com/Messenger/negotiate

Signalr Issue on Azure Service Fabric: Error during WebSocket handshake

We are using Service Fabric for hosting our messaging service ASP.NET Core web API (leveraging signalr) and React web application as a client. Everything works exactly as expected on local machines but not on Azure. We have configured CORS policies for cross-origin handling since the service and the web app are hosted on different servers. Configured sticky sessions in load balancer. This CORS Policy works in local machine with the service and client hosted on different ports.
Post hosting the application on Azure, I get an Error in the browser console as
Error during WebSocket handshake: Unexpected response code: 500
The issue is very likely to be happening because of CORS.
Looking the screenshot you provided, it is possible to see the CORS exception and, as you are aware, the front-end application calling the SignalR service are hosted on different locations(The domain is the same but different ports).
The CORS settings you applied probably didn't work.
You have two solutions:
Configure CORS in the ASP.NET CORE, so SignalR can accept the call from other domains.
Host both on same domain + port to avoid CORS

Resources