Cordova, AngularJs, WebApi and CORS

We have a simple website with some data stored in Azure Table Storage. From a Cordova app we request the data from the webapi we have added to the website. This works great when running on the device, but not when testing locally: Cross-Origin Resource Sharing (CORS) won’t let us.

Google sugested creating a proxy and setting it during build. But we went a different route. The webapi was ours, we should simply allow CORS. This is done with a nuget package: Microsoft.AspNet.WebApi.Cors and some configuration.

using System.Web.Http.Cors;
public static class WebApiConfig {
   public static void Register(HttpConfiguration config) {
      // Web API configuration and services
      var cors = new EnableCorsAttribute("*", "*", "*");
      config.EnableCors(cors);
      // .. more config ...
   }
}

About erictummers

Working in a DevOps team is the best thing that happened to me. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Development and tagged , . Bookmark the permalink.

3 Responses to Cordova, AngularJs, WebApi and CORS

  1. Pingback: Cordova, AngularJs, WebApi and CORS - Angular News

  2. Pingback: Webapi core 2.1 and jQuery (CORS) | .NET Development by Eric

  3. Pingback: Webapi core 2.1 and jQuery (CORS) | .NET Development by Eric

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.