-3

My Ionic-Angular front end is trying to get data from a C# ASP.NET Webapi, both hosted as Azure App services.

It works fine when using https but not when using http. enter image description here

I've tried different configurations in my startup.cs, but somehow it doesn't go through:

opt.AddPolicy("CorsPolicy", policy =>
                    {
                        policy
                        .AllowAnyOrigin()
                        .AllowAnyHeader()
                        .AllowAnyMethod();
            
                        // policy.AllowAnyHeader().AllowAnyMethod().WithOrigins("http://localhost:8100");
                    });
   opt.AddPolicy("CorsPolicy", policy =>
                    {
                        policy
                        .WithOrigins("https://cappuccinobudget.azurewebsites.net", 
                                     "http://cappuccinobudget.azurewebsites.net" )
                                     .AllowAnyHeader()
                                     .AllowAnyMethod();
            
                        
                    });

Any tips?

Pablo Aguirre de Souza
  • 3,939
  • 4
  • 14
  • 30

1 Answers1

0

try to replace your Cors syntax with this

services.AddCors(o => o.AddPolicy("CorsPolicy",
                    builder =>
                    {
                       builder.WithOrigins("http://localhost:8100")
                       .AllowAnyMethod()
                       .AllowAnyHeader();
            }));
.....

    app.UseCors("CorsPolicy");
Serge
  • 40,935
  • 4
  • 18
  • 45