From cae6a7795b89ee89bd5c79e7d535649d5e3cd76d Mon Sep 17 00:00:00 2001 From: tactile Date: Tue, 20 Jan 2026 15:56:52 +0500 Subject: [PATCH] fix CORS --- backend-dotnet/Program.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/backend-dotnet/Program.cs b/backend-dotnet/Program.cs index 908356a..8630cfd 100644 --- a/backend-dotnet/Program.cs +++ b/backend-dotnet/Program.cs @@ -22,6 +22,17 @@ ValidateConfiguration(config); ConfigureJwtAuthentication(builder.Services, config); +builder.Services.AddCors(options => +{ + options.AddDefaultPolicy(policy => + { + policy.WithOrigins(config.AllowedOrigins) + .AllowAnyMethod() + .AllowAnyHeader() + .AllowCredentials(); + }); +}); + builder.Services.AddAuthorization(); builder.Services.ConfigureHttpJsonOptions(options => @@ -32,15 +43,7 @@ builder.Services.ConfigureHttpJsonOptions(options => var app = builder.Build(); Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true; -var currentConfig = app.Services.GetRequiredService(); - -app.UseCors(policy => -{ - policy.WithOrigins(currentConfig.AllowedOrigins) - .AllowAnyMethod() - .AllowAnyHeader() - .AllowCredentials(); -}); +app.UseCors(); app.UseAuthentication(); app.UseAuthorization();