I am trying to migrate a project from asp.net Core 2.2.6 to asp.net core 3.0 In my startup I had
services.AddMvc(options =>
{
options.Filters.Add(new CorsAuthorizationFilterFactory("default"));
})
When I update to netcoreapp3.0 I receive the following error The type or namespace name 'CorsAuthorizationFilterFactory' could not be found (are you missing a using directive or an assembly reference?)
Does anyone know what is the equivalent to asp.net core 3?
In ASP.NET Core 3.0 and later versions, CORS is configured differently than in earlier versions. The CorsAuthorizationFilterFactory is not used in the same way.
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy("default", builder =>
{
builder.WithOrigins("yoursite")
.AllowAnyHeader()
.AllowAnyMethod();
});
});
And then in your configure method
app.UseCors("default");
This must rid of this error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With