Enable CORS in Minimal API

Ron*_*ano 5 .net c# .net-6.0

I have this code from Microsoft docs minimal apis CORS, when I run it I don't understand why the endpoints returns 200 OK when the CORS is enabled.

What should be the expected result when the endpoints are consumed?


const string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddCors(options =>
{
    options.AddPolicy(name: MyAllowSpecificOrigins,
                      builder =>
                      {
                          builder.WithOrigins("http://example.com",
                                              "http://www.contoso.com");
                      });

});

var app = builder.Build();
app.UseCors();

app.MapGet("/cors", [EnableCors(MyAllowSpecificOrigins)] () =>
                           "This endpoint allows cross origin requests!");
app.MapGet("/cors2", () => "This endpoint allows cross origin requests!")
                     .RequireCors(MyAllowSpecificOrigins);

app.Run();
Run Code Online (Sandbox Code Playgroud)