From d122b437bc4188c1188418a45d212474e54013a5 Mon Sep 17 00:00:00 2001 From: hz Date: Mon, 12 May 2025 19:55:02 -0700 Subject: [PATCH] Cors --- Program.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Program.cs b/Program.cs index 768e20b..a6e829c 100644 --- a/Program.cs +++ b/Program.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.IdentityModel.Tokens; using System.Text; +using Microsoft.AspNetCore.Http; var builder = WebApplication.CreateBuilder(args); builder.WebHost.ConfigureKestrel(serverOptions => {}); @@ -82,6 +83,19 @@ builder.Services.AddCors(options => var app = builder.Build(); app.UseCors("AllowAll"); + +// Enable OPTIONS requests to reach controllers +app.Use(async (context, next) => +{ + if (context.Request.Method == HttpMethods.Options) + { + context.Response.StatusCode = 204; + return; + } + + await next(); +}); + app.UseSwagger(); app.UseSwaggerUI();