I currently have an ASP.NET MVC application. I want to convert a portion of the application to a Single Page App with Angular. My plan is to create a new project in the solution that is just the Angular CLI development environment. The build output will be in a folder in my original ASP.NET project. For development I want to enable CORS to properly communicate between the two projects. Both will be served on localhost on different ports.
I've looked over solutions offered on this Stack Overflow question
but it doesnt complete the picture. I've updated my web.config with the following:
<add name="Access-Control-Allow-Origin" value="https://localhost:4200"/>
This allows me to hit the route but I still get a 404 with the OPTIONS preflight request. From what I've read on Stack Overflow and in the Microsoft Docs
, I need to add
on the class or controller I want to hit. However this alwasys assumes I'm working with a Web API and not MVC.
How can I enable CORS for development only in an ASP.NET MVC project?