Search code examples
asp.net-web-apiionic-frameworkionic-view

Ionicview and ionic serve CORS


My ionic app is connecting to asp.net web api on azure. The API already allow all origin to access and the API_KEY header. However I am still getting Message "The origin 'http://localhost:8100' is not allowed." on both Ionic serve and ionic view

Code in ionic app

var headers = new Headers();
headers.append('API_KEY', 'X-some-key');
headers.delete("Origin");
let options = new RequestOptions({ headers: headers});
return this.http.get(url, options);

request and response header when using ionic serve image


Solution

  • Found the answer from here : CORS enabled but response for preflight has invalid HTTP status code 404 when POSTing JSON

    The problem is backend doesn't have OPTIONS handler, added OPTIONS handler in web.config works.