I was creating an Angular application which called a Web API project in VS Code. The projects had different port numbers on my local machine, as you would expect. When I started the API project and then the Angular site, the data wasn’t being returned to my template as expected. Looking at the Chrome console, I discovered this message:
Ah, the CORS issue.
Luckily, there was a helpful document on the Microsoft site that led me to the solution. So open the Startup.cs file in your Web API project and make modifications to do areas. In the ConfigureServices method, add the following line:
In the Configure method, add the UseCors statement:
You’ll notice that I only enabled at the port I was interested in. There is a nice Stack Overflow post on expanding that to include a broader range of requests.