Using CORS to Use API applications from JavaScript, corsapi
The Application Service provides built-in cross-origin Resource Sharing (CORS) support, allowing JavaScript clients to call APIs hosted in API applications across domains. Application Service allows you to configure CORS access to APIs without writing any code in the APIs.
This article contains two parts:
The section "how to configure CORS" describes how to configure CORS for any API application, Web application, or mobile application. This section applies to all frameworks supported by application services, including. NET, Node. js, and Java.
This article begins with the introduction to. NET to demonstrate CORS support. The content is based on the work completed in the first API application getting started tutorial.
How to configure CORS in Azure Application Service
You can configure CORS In the Azure portal or by using the Azure Resource Manager tool.
Configure CORS In the Azure Portal
3. In the "Settings" tab on the right of "API application", find the "API" section and click "CORS ".
4. In the text box, enter one or more JavaScript calls to the source URL.
For example, if you have deployed a JavaScript Application to a Web application named todolistangular, enter "https://todolistangular.chinacloudsites.cn ". Alternatively, enter an asterisk (*) to specify that all original fields are accepted.
5. Click Save ".
After you click Save, the API application accepts JavaScript calls from the specified URL.
Configure CORS using Azure Resource Manager
You can also use Azure Resource Manager templates in command line tools such as Azure PowerShell and Azure CLI to configure CORS for API applications.
For examples of Azure Resource Manager templates that can set CORS properties, open the azuredeploy. json file in the example application repository in this tutorial. Find the template section shown in the following example:
"cors": { "allowedOrigins": [ "todolistangular.chinacloudsites.cn" ] }
To continue learning the. NET getting started tutorial, click here.