Saturday, December 12, 2015

Set up CORS in a modern Visual Studio 2015 MVC5 application which mixes MVC and the Web API.

  1. Go to: Tools > NuGet Package Manager > Package Manager Console
  2. Change the "Package source:" dropdown to be "nuget.org"
  3. Type in: Install-Package Microsoft.AspNet.Cors
  4. Put config.EnableCors(); in WebApiConfig which is a class found in the App_Start folder.
  5. Now slap [EnableCors(origins: "*", headers: "*", methods: "*")] on a Web API controller. It should work!

 
 

Addendum 12/20/2019: In modern times Install-Package Microsoft.AspNet.WebApi.Cors is probably the thing to use in step three above.

No comments:

Post a Comment