azure-docs icon indicating copy to clipboard operation
azure-docs copied to clipboard

Problem with Azure SignalR service connection while using custom domain in ASP.NET (not Core)

Open tajwan69 opened this issue 1 year ago • 8 comments

Hi,

I have a problem with communication with Azure SignalR service when I try to use created custom domain (step by step using this tutorial). In SignalR settings I use Default service mode and I have a Premium tier. When I created custom domain I verified it using health check API and it return 200 status code without any certificate error.

I tried on sample ChatRoom ASP.NET project downloaded from official AzureSignalR-samples. Sample app link: https://github.com/aspnet/AzureSignalR-samples

When I use standard SignalR url in connection string everythink works fine. There is a log from correct situation: image

But when I change Endpoint property in SignalR connection string to my custom domain a have a problems. There is a log from incorrect situation (custom domain): image

As you can see, in custom domain case there is a very strange situation, because signalR try connect with localhost domain (not custom domain). In correct situaction SingalR correct generate url to negotiation step and I see line "Auto detected cross domain url", but in custom domain situation there not any this type logs. Why? Where is the difference?

But I was able to move forward when I added an extra line of code in the JS code: $.connection.hub.url = "my_signalr_service_custom_domain_url"; image

Now negotiating url is good (custom domain) but then I have a different problem with "CORS Missing Allow Origin" and I don't have idea how to deal with it. Of course in CORS settings in SignalR Service on Azure portal I have "*" (all permitted sources). In addtion setting second time custom url (in JS code) in not good for me.

Why custom domain not working from connection string and next how to deal with "CORS Missing Allow Origin" problem ?


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

tajwan69 avatar Oct 11 '22 12:10 tajwan69

@tajwan69 Thanks for your feedback! We will investigate and update as appropriate.

Naveenommi-MSFT avatar Oct 11 '22 13:10 Naveenommi-MSFT

@RyanHill-MSFT Do you have any feedback about my problem? I really care about solving my issue.

tajwan69 avatar Oct 17 '22 07:10 tajwan69

Internal server error means that in your app server, the server connections failed to connected to the service.

When using custom domain following https://learn.microsoft.com/en-us/azure/azure-signalr/howto-custom-domain?tabs=vault-access-policy%2Cazure-powershell, the Endpoint value of connection string for SignalR service should be automatically updated to the custom domain value. Are you using that connection string in your app server? Are you seeing server connections trying to connect to your Azure SignalR in your app server side logs? If there are errors, what are the error logs?

vicancy avatar Oct 17 '22 10:10 vicancy

Hi @vicancy, thanks for reply. I created custom domain using this tutorial step by step and at the end I verified it by GET request to "my_custom_domain_url/api /health" and I get 200 status response code.

But you wrote that "the Endpoint value of connection string for SignalR service should be automatically updated to the custom domain value". When I see on the my SignalR Azure Portal site, my host name not updated to new custom domain and connection strings not updated too. Should this be updated to custom domain url?

Overview tab: image

Connection strings tab: image

In addition when I try to use custom domain url in Live trace tool I don't see any logs.

tajwan69 avatar Oct 18 '22 08:10 tajwan69

Have you tried Endpoint=https://<custom-domain>;... as you connection string? Also please share your app server side error logs.

ArchangelSDY avatar Oct 19 '22 08:10 ArchangelSDY

@ArchangelSDY Yes of course. As I said on the top: "But when I change Endpoint property in SignalR connection string to my custom domain a have a problems."

And I don't have any errors on app server side.

tajwan69 avatar Oct 19 '22 11:10 tajwan69

When running your app server for example using dotnet run, there would be logs similar to:

info: Microsoft.Azure.SignalR.Connections.Client.Internal.WebSocketsTransport[1]
      Starting transport. Transfer mode: Binary. Url: 'wss://xxx.service.signalr.net/server/?hub=chathub&cid=7a55407b-aa7c-4fc3-8003-be2a6ff18368'.
info: Microsoft.Azure.SignalR.StrongServiceConnectionContainer[1]
      Hub 'ChatHub' is now connected to '(Primary)https://xxx.service.signalr.net(hub=ChatHub)'.

Or when failure case:

info: Microsoft.Azure.SignalR.Connections.Client.Internal.WebSocketsTransport[1]
      Starting transport. Transfer mode: Binary. Url: 'wss://xxx.service.signalr.net/server/?hub=chathub&cid=7273c67f-2e13-47ea-b862-42ef6f1540fd'.
info: Microsoft.Azure.SignalR.Connections.Client.Internal.WebSocketsTransport[6]
      Transport is stopping.
fail: Microsoft.Azure.SignalR.ServiceConnection[2]
      Failed to connect to '(Primary)https://xxxservice.signalr.net(hub=ChatHub)', will retry after the back off period. Error detail: ***THE ERROR DETAIL*** Id: 7273c67f-2e13-47ea-b862-42ef6f1540fd

There should be error details in the fail log.

Do you see anything similar in your app server side? If not, you can enable your server side log by adding the below lines into your appsettings.Development.json Logging section:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    }
  },
  ...
}

vicancy avatar Oct 21 '22 01:10 vicancy

Hi, @vicancy. Thanks for reply. You are right. I see errors on my app server side in Output window when run ChatRoom sample application with custom domain url connection string.

Microsoft.Azure.SignalR Information: 0 : [Microsoft.Azure.SignalR.Connections.Client.Internal.WebSocketsTransport]Starting transport. Transfer mode: Binary. Url: 'wss://MY_CUSTOM_DOMAIN_URL/aspnetserver/?hub=chatroom.startup_chatroom.startup&cid=d8b11477-9a30-4d4a-83c9-7e6248e66da8'.
Microsoft.Azure.SignalR Information: 0 : [Microsoft.Azure.SignalR.Connections.Client.Internal.WebSocketsTransport]Starting transport. Transfer mode: Binary. Url: 'wss://MY_CUSTOM_DOMAIN_URL/aspnetserver/?hub=chatroom.startup_chatsamplehub&cid=33262cc5-0dc4-4157-8439-654ceacae5d0'.
Microsoft.Azure.SignalR Information: 0 : [Microsoft.Azure.SignalR.Connections.Client.Internal.WebSocketsTransport]Transport is stopping.
Microsoft.Azure.SignalR Information: 0 : [Microsoft.Azure.SignalR.Connections.Client.Internal.WebSocketsTransport]Transport is stopping.
Microsoft.Azure.SignalR Error: 0 : [Microsoft.Azure.SignalR.AspNet.ServiceConnection]Failed to connect to '(Primary)https://MY_CUSTOM_DOMAIN_URL(hub=ChatRoom.Startup)', will retry after the back off period. Error detail: Nie można połączyć się z serwerem zdalnym. Serwer zdalny zwrócił błąd: (400) Złe żądanie.. Id: d8b11477-9a30-4d4a-83c9-7e6248e66da8
Microsoft.Azure.SignalR Error: 0 : [Microsoft.Azure.SignalR.AspNet.ServiceConnection]Failed to connect to '(Primary)https://MY_CUSTOM_DOMAIN_URL(hub=ChatSampleHub)', will retry after the back off period. Error detail: Nie można połączyć się z serwerem zdalnym. Serwer zdalny zwrócił błąd: (400) Złe żądanie.. Id: 33262cc5-0dc4-4157-8439-654ceacae5d0
Microsoft.Azure.SignalR Error: 0 : [Microsoft.Azure.SignalR.StrongServiceConnectionContainer]Hub 'ChatSampleHub' is now disconnected from '(Primary)https://MY_CUSTOM_DOMAIN_URL(hub=ChatSampleHub)'. Please check log for detailed info.
Microsoft.Azure.SignalR Error: 0 : [Microsoft.Azure.SignalR.StrongServiceConnectionContainer]Hub 'ChatRoom.Startup' is now disconnected from '(Primary)https://MY_CUSTOM_DOMAIN_URL(hub=ChatRoom.Startup)'. Please check log for detailed info.

Of course MY_CUSTOM_DOMAIN_URL is good custom domain url which I created using tutorial.

So there is a 400 Bad Request Error. When I changed url to standard url signal service url (not custom) everythink works fine and I dont have these errors.

tajwan69 avatar Oct 21 '22 11:10 tajwan69

Hi @tajwan69, really appreciate your support in reporting the issue. Could you email me lianwei(at)microsoft.com your Azure SignalR resource name for me to take a deep look?

vicancy avatar Oct 24 '22 02:10 vicancy

Is it possible that there are any rules blocking path "/aspnetserver" on your custom domain side?

vicancy avatar Oct 24 '22 03:10 vicancy

Hi @vicancy, I sent you email message with informations about my Azure SignalR resource name.

I don't have any blocking rules on my custom domain side. I host my sites on cloudflare services.

tajwan69 avatar Oct 24 '22 11:10 tajwan69

Looks like HTTP headers required by WebSocket requests ( Connection: Upgrade and Upgrade: websocket ) are removed by cloudflare service.

vicancy avatar Oct 25 '22 11:10 vicancy

Exactly, that was my problem. My websocket support settings were disabled on the cloudflare service where I hosted my azure SignalR service.

@vicancy Thanks for helping and solving my problem.

tajwan69 avatar Nov 07 '22 07:11 tajwan69