Azure / azure-signalr

Azure SignalR Service SDK for .NET

Home Page:https://aka.ms/signalr-service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SignalR negotiate url not working with custom base url but working with default domain of Azure app

shubhjack opened this issue · comments

I have a dotnet core api app hosted on Azure app service(PaaS). I have implemented signalr service in this. Client side they call the negotiate url to get the connection Id.

Issue:
negotiate url is giving 404 with custom endpoint. Its working with App service default domain.
{BaseUrl}/notify/negotiate => 404
{appname.azurewebsites.net}/notify/negotiate => giving proper response

Since this was not working so I created a separate signalr Service as well but that is also giving the same issue.
Please help me out if someone has any kind of solution.

{BaseUrl}/notify/negotiate => 404
{appname.azurewebsites.net}/notify/negotiate => giving proper response

This is the request to your app service, it hasn't yet had Azure SignalR involved.

Some idea to troubleshoot the issue: expose one endpoint in your app server side, for example "{appname.azurewebsites.net}/test", and try with "{BaseUrl}/test" to see if it works, if it does not, it means there might be some mapping issues between your custom endpoint and app service.

{BaseUrl}/notify/negotiate => 404
{appname.azurewebsites.net}/notify/negotiate => giving proper response

This is the request to your app service, it hasn't yet had Azure SignalR involved.

Some idea to troubleshoot the issue: expose one endpoint in your app server side, for example "{appname.azurewebsites.net}/test", and try with "{BaseUrl}/test" to see if it works, if it does not, it means there might be some mapping issues between your custom endpoint and app service.

It's an API project in which I require SignalR call in one of the api. My other endpoints are working fine. This /notify route is also working on localhost but after deploying it's not working with my api base url but only with the default domain url of app service.

Is it possible that subpaths are not supported in your API? for example, does /test/test1 work?
One way to debug is adding some logs whenever any HTTP requests come into your app server, it can check 1. If the request arrives at your app server 2. If the incoming request path is as expected

Yes the subpaths are allowed and other api endpoints are working perfectly with that base url. {BaseUrl}/api/{Controller}/{Action}/{optional param} => working
{BaseUrl}/notify => not working.
Actually this code is working in the project hosted in IaaS. But we are moving our backend to PaaS on Azure Web App, so not sure if there is any extra configuration needed or not.

Below is the Cors policy I added and you can see subdomains are allowed in that.
`services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder =>
{
builder.WithOrigins(policyOrigins)
.SetIsOriginAllowedToAllowWildcardSubdomains()
.AllowCredentials()
.AllowAnyHeader()
.WithMethods(allowedMethods);
});
});

services.AddSignalR().AddAzureSignalR("Connection String");`

and below is configured in Configure Method
app.UseEndpoints(endpoints => { endpoints.MapHub<NotificationHub>("/notify"); endpoints.MapDefaultControllerRoute(); endpoints.MapRazorPages(); endpoints.MapControllerRoute("DefaultApi", "{controller=Home}/{action=Index}/{id?}"); endpoints.MapControllerRoute("default", "{controller}/{action}/{id?}"); });

So we had to configure 3 endpoints in our APIM for Signalr

  1. Negotiate 2. preflight for negotiate url 3. Websocket url