pkskelly / BlazorGolf

Blazor and Web API sample application to learn api design and blazor
MIT License
0 stars 0 forks source link

Enable multiple CORS policies #30

Open pkskelly opened 2 years ago

pkskelly commented 2 years ago

Add multiple CORS policies in Program.cs to enable Development and Production CORS Policies in place.

pkskelly commented 2 years ago

See Enable Cross-Origin Requests (CORS) in ASP.NET Core to enable Dev/Prod settings using multiple policies. Similar to below create Policies that can be applied based on the Environment.

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

    options.AddPolicy("AnotherPolicy",
        builder =>
        {
            builder.WithOrigins("http://www.contoso.com")
                                .AllowAnyHeader()
                                .AllowAnyMethod();
        });
});