This is a quick post on how to enable CORS in Web API 2. It’s actually fairly an easy task. First you need to install Microsoft.AspNet.WebApi.Cors nuget package to the Web API project. You can do it from either of following ways.
1. Nuget Packet Manager
2. Package Manager Console
Then modify the Register method in WebApiConfig.cs as follows.
Make sure to add using System.Web.Http.Cors. You can customize the policy by setting different values to EnableCorsAttribute properties.Happy Coding.