0

I add UseAuthentication(); to my startup.cs The Allow cors fail and the cors is not allowed, there's any order to setup please? (without app.UseAuthentication() no cors problem)

  public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {

        app.UseHttpsRedirection();
        app.UseRouting();
        app.UseCors(
options => options.AllowAnyOrigin()
      .AllowAnyMethod()
      .AllowAnyHeader()
  ); app.UseHttpStatusCodeExceptionMiddleware();
        app.UseAuthentication();

on ConfigureServices i have :

  void ConfigureServices(IServiceCollection services)
{....       


        services.AddCors();
                services.AddSSOAuthentication(Configuration, CurrentEnvironment);
                services.AddControllers();
                services.AddRequestLogging(opt =>
                {
                    opt.ResponseTimeInMs = true;
                    opt.CookiesLoggingEnabled = false;
                });
                services.AddSwaggerGen();
    
            }

enter image description here

user1428798
  • 1,534
  • 3
  • 24
  • 50

2 Answers2

0

Did you add

services.AddCors(options =>
            {
                ...
            });

to ConfigureServices?

Aurimas
  • 145
  • 1
  • 1
  • 7
0

This is working for me:

readonly string MyAllowSpecificOrigins = "AnyPolicyName";

public void ConfigureServices(IServiceCollection services)
    {
        services.AddCors(options =>
        {
            options.AddPolicy(MyAllowSpecificOrigins,
                                builder =>
                                {
                                    builder.AllowAnyOrigin();
                                });
        });
    
        /** etc. **/
    }

EDIT: Also add

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    /*...*/

    app.UseCors(MyAllowSpecificOrigins);

    /*...*/
}
MartinM43
  • 101
  • 1
  • 1
  • 8