Enable CORS in .Net Web Api 2

What is CORS?

Cross-origin resource sharing (CORS) is a mechanism that enables many resources (e.g. fonts, JavaScript, etc.) on a web page to be requested from another domain outside the domain from which the resource originated. (wiki)

  1. You need to install Microsoft.AspNet.WebApi.Cors

PM> Install-Package Microsoft.AspNet.WebApi.Cors

2. In your WebApiConfig.cs in Register method

3. In you Web.config

Make sure you have the following

4. And the last step is to use Cors attributes in your controller like this

If you still have issues, please comment this article.

Building the future, team visibility advocate

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store