DKNet

Configure an explicit CORS policy

Part of DKNet.AspCore.Extensions. AddCorsConfig reads allowed origins and installs a default policy only when at least one nonblank origin is configured. UseCorsConfig calls UseCors only if registration set its feature marker.

using DKNet.AspCore.Extensions.Hosting;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCorsConfig(builder.Configuration);
var app = builder.Build();
app.UseCorsConfig();
Console.WriteLine("CorsConfig pipeline configured.");

Configure an explicit CORS policy: the host registers settings and the matching Use method installs middleware only when its feature marker exists.

⚙️ Configuration reference

Configuration key Type Default Effect
Cors:AllowedOrigins string[] empty No policy or marker when empty after dropping blank entries.
Cors:AllowedMethods string[] GET, POST, PUT, PATCH Methods on the default policy.
Cors:AllowedHeaders string[] Authorization, Content-Type, Accept, X-Idempotency-Key Headers on the default policy.

⚠️ Gotchas & limits