First, we need to enable CORS in WebAPI, then we call the service from other application AJAX request. In order to enable CORS, we need to install the JSONP package from NuGet (see Figure3). After adding Jsonp package, we need to add the following code-snippet in App_Start\WebApiConfig. cs file.
This class defines an attribute that can be applied to an action or a controller to enable CORS. By default, it allows all origins, methods and headers. Namespace: System.Web.Http.Cors.
Use Nuget, Microsoft use it for many great things as well.
Go to: TOOLS > Library Package Manager > Package Manager Console, and type in:
Install-Package Microsoft.AspNet.WebApi.Cors
Reference to the Nuget package here.
Here's another question on this topic
Answer from @Marcus is now outdated, System.Web.Http.Cors
is no longer comes with Microsoft.AspNet.WebApi.Cors
follow this link to install System.Web.Http.Cors
Microsoft.AspNet.Cors
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With