From 85db5b9159580e1b3d22d8df058c2fd84434af1f Mon Sep 17 00:00:00 2001 From: Robin-Manuel Thiel Date: Fri, 20 Oct 2023 16:47:51 +0200 Subject: [PATCH] Fix order of adding CORS --- src/Wemogy.AspNet/Startup/StartupExtensions.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Wemogy.AspNet/Startup/StartupExtensions.cs b/src/Wemogy.AspNet/Startup/StartupExtensions.cs index 57c5bf2..51ce0ee 100644 --- a/src/Wemogy.AspNet/Startup/StartupExtensions.cs +++ b/src/Wemogy.AspNet/Startup/StartupExtensions.cs @@ -86,6 +86,10 @@ public static void UseDefaultSetup(this IApplicationBuilder applicationBuilder, applicationBuilder.UseDeveloperExceptionPage(); } + // Must come before any "UseSwagger()" calls because the Swagger middleware, when it knows that the request + // is for Swagger, it doesn't forward the request onto the next middleware, it just immediately returns. + applicationBuilder.UseDefaultCors(); + if (options.OpenApiEnvironment != null) { applicationBuilder.UseDefaultSwagger(options.OpenApiEnvironment); @@ -103,8 +107,6 @@ public static void UseDefaultSetup(this IApplicationBuilder applicationBuilder, applicationBuilder.UseCloudEvents(); } - applicationBuilder.UseDefaultCors(); - applicationBuilder.UseAuthentication(); applicationBuilder.UseAuthorization();