adsense

Saturday, December 30, 2023

Fixing 'Access-Control-Allow-Origin' error in ASP.NET Core 6/7

 When working with a WEB API if you want to share resources between different domains we need to enable CORS in Program.cs as shown below.


app.UseCors(builder => builder
       .AllowAnyHeader()
       .AllowAnyMethod()
       .AllowAnyOrigin()
    );

Note that it is recommended to have this after app.UseRouting(); middleware.

Cheers,
Samitha

No comments:

Post a Comment