Open Closed

SignalR not being established for MVC public web app #4648


User avatar
0
Sturla created

Hi

We are having problems connecting SignalR to the public MVC page and are getting the following error

We have successfully been using SignalR for our Blazor WASM backend (hosted as static website in Azure) so we know all about how SignalR should work (or we thought at least).

We have been trying all kinds versions of CORS settings in HttpApi.Host without luck

This didn´t do anything (now we are just using app.UseCors())

  app.UseCors(x => x
           .AllowAnyMethod()
           .AllowAnyHeader()
           .SetIsOriginAllowed(origin => true)
           .AllowCredentials());

Is there a documentation or some other steps that we might be missing for for connecting with signalR in MVC public web app?

  • ABP Framework version: 7.0.2
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated: yes

8 Answer(s)
  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    You are using wildcard ('*') with .AllowCredentials. You need to whitelist the origins.

    You can configure CORS in publicwebdev app as:

    context.Services.AddCors(options =>
    {
        options.AddDefaultPolicy(builder =>
        {
            builder
                .WithOrigins("https://eventstreamingapidev.azurewebsites.net")
                .WithAbpExposedHeaders()
                .SetIsOriginAllowedToAllowWildcardSubdomains()
                .AllowAnyHeader()
                .AllowAnyMethod()
                .AllowCredentials();
        });
    });
    
  • User Avatar
    0
    Sturla created

    Hi @gterdem, thanks for the answer

    We have been trying to use this without luck. Is there something more we need to do? There is some puzzle missing..

  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    Did you also add https://eventstreamingpublicwebdev.azurewebsites.net to https://eventstreamingapidev.azurewebsites.net CORS origins?

    Can you try removing .AllowCredentials(); and test again?

  • User Avatar
    0
    alper created
    Support Team Director

    the question has been reopened due to the owner's request

  • User Avatar
    0
    Sturla created

    For some reason we are not getting this to work. We are now on 7.1.1 but that doesn´t seem to matter.

    Here are is our setup. Do you see something wrong/missing here?

    This is our httpApi.Host setup

    and this is our Web.Public one

  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    Did you try removing .AllowCredentials(); and tested again?

    Do you still get the same error? Did you check the appsettings.json file is overridden correctly on deployment?

  • User Avatar
    0
    Sturla created

    Hi @gterdem

    As you can see in my images there is no .AllowCredentials(); we have removed that. Here is our settings file and looking at it it looks like we are missing the CORS settings... correct?

  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    Yes, if you can check the module ConfigureServices method that has CORS configuration, you are basically missing it.

    You may also forget to override it on production environment aswell.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38