I’m getting this error while calling the .NET framework APIs, which are running on a Mac machine.
CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I enable the CORS globally and on the controller, both work when the endpoints are hit on the local system, but when trying to hit from a remote Mac machine get the above error. I tried a different approach.
Could anyone please tell me the exact procedure to achieve this?
The default origins required for a Capacitor app are as follows:
- iOS:
capacitor://localhost
- Android:
http://localhost
- Android:
https://localhost
How have you configured your .NET API?
It would be helpful to shows code examples…shows your code on your API where you enabled CORs.
I’m using Cordova, and the backend is on .NET WebForms. The CORS is defined properly as per the official document, and this backend is on a Windows machine, and the Ionic Angular app is running on a Mac. So, where I’m trying to hit the controller, the APIs are taking a bit longer time and then giving the below error:
net::ERR_ADDRESS_ERROR
My ques is how to call the APIs in my scanerio or is that possible or not?
That could be a firewall issue on the Windows machine. Is the firewall on and if so, have you opened the the port the .NET API is running on so traffic from the Mac can access it? This is also assuming they are on the same network.
The CORS error is probably coming up because the OPTIONS request for the CORS headers is being blocked by your Windows firewall.
Seeing your CORS code/config would also still be helpful as Hills90210 said.
1 Like