How to resolve Strict Origin Error at angular app

442 Views Asked by At

I have enabled Cors in ASP.Net Core API but after publishing I am still getting error with strict-origin-when-cross-origin.My Program.cs looks like below. I have tried other ways to add the URL of the client as well. I am not sure what causing this error. Any help is appreciated.

  var builder = WebApplication.CreateBuilder(args);

                builder.Services.AddCors();

                builder.Services.AddControllers();
                builder.Services.AddRazorPages();

                var app = builder.Build();

                app.UseHttpsRedirection();
                app.UseStaticFiles();
                app.UseRouting();

                app.UseCors(x => x
                                .AllowAnyMethod()
                                .AllowAnyHeader()
                                .SetIsOriginAllowed(origin => true) // allow any origin
                                .AllowCredentials()); // allow credentials

                app.UseAuthorization();

                app.UseEndpoints(x => x.MapControllers());

                app.Run();

I have followed all possible ways listed on MS Website. https://learn.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-7.0

0

There are 0 best solutions below