The cors policy adds cross-origin resource sharing (CORS) support to an operation or an API to allow cross-domain calls from browser-based clients.
You need to enable CORS (cross-origin resource sharing) on your APIs to let the visitors of your portal test the APIs through the built-in interactive console. For more details of this policy refer to:
Adding CORS Policy in API Management
In your API management Portal go to your API and select all operations and click on Inbound processing.
Apply the Cors Policy as follow in Inbound section and click on save.
Note: This is a general cors policy and can be customized as per requirements.
According to our scenario now we can modify the cors policy to avoid unnecessary access as follows:
This is an optional setup if you want to directly enable cors policy without following the method as mentioned in steps 1 and 2 above.
In your API management portal go to the Portal overview section in the left pane and click on ‘Enable CORS’ button. Click on manually apply it on Global Level to enable CORs at a global level.
Verify your CORs Policy is applied
Step 1: Click on the Developer Portal.
Step 4: Copy the URL at Top and Open in new Brower and click on APIs Tab in Navigation Pane at Top on the Webpage.
Step 5: Select your API.
Step 6: Click on try it option.
Step 7: Enter the Subscription Key and click on send.
Step 8: Note the Response.
Thus we have successfully applied as well as verified the CORs Policy in API management and solved the CORs Error.