Using CORS to Use API applications from JavaScript, corsapi

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.