0

I have created simple API in MVC.

I want to call it from Ionic App. I wrote code in my WebApiConfig.cs file to allow CORS. But when I try to call same from Ionic it throws an error:

Failed to load http://localhost:53377/api/member/2: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.

How can I resolve the issue?

Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130
amol
  • 1
  • 1

2 Answers2

0

In each applications when you are going to send requests to another web application, you must set the Access-Control-Allow-Origin header.

This post has complete info about it.

Access-Control-Allow-Origin header

Iman Bahrampour
  • 6,180
  • 2
  • 41
  • 64
0

My English is not good, but I will try to help you.

Add this in your web.config

  <httpProtocol>
   <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Headers" value="Content-Type" />
    <add name="Access-Control-Allow-Methods" value="GET" />
  </customHeaders>
</httpProtocol>

See your requisitions allowed in Access-Control-Allow-Methods. Add GET, POST, PUT OR DELETE according to your need.

Alert: I don't know of informations of security about it. But in simple requisition, should solve.

Alert 2: I reccomend to pass a security token in webapi requisition.