A practical walkthrough for setting up CORS in a .NET 6 Web API application. Covers creating a Web API and a separate web application, reproducing the CORS error by calling the API from a different origin via JavaScript fetch, and fixing it by configuring a CORS policy in Program.cs using AddCors and UseCors with the allowed origin and port specified.
Table of contents
1. My Web API application2. Some other web application needs to call my API with JavaScript3. The CORS error4. The fix18 Impressions1 Comment