ASP. NET Core Webapi Getting Started (iii) cross-domain processing

Source: Internet
Author: User

One, the cross-domain processing in Core webapi

1. Cross-domain processing is almost always used when using the WEBAPI project

2.Core Webapi project with cross-domain cors processing, no need to add packages separately

3. Simple method of Use

Ii. Examples of Use

1. Cross-domain processing is enabled in the global configuration, named ' Any ', which can be accessed

void configureservices (iservicecollection services) {    // Configure cross-domain processing    services. Addcors (options =        options. Addpolicy ("any", builder =        {            // allow host access to any source             . Allowanymethod ()            . Allowanyheader ()            . Allowcredentials (); // Specify processing Cookies         });    });}

2. Use the cross-domain rule of the corresponding name on the controller or the action's method note,

[Enablecors ("any")]

    [Produces ("Application/json")]    [Route ("Api/menu")]    [Enablecors ("any")] // set up agents for cross-domain processing Public     class Menucontroller:controller    {    }

Note: If specified on the controller, all action within the controller has a corresponding cross-domain limit.

Third, when cross-domain, the use of cookies

More:

ASP. NET Core Webapi get started (b) Simple example

ASP. NET Core Webapi Getting Started (i)

JSON serialization processing in ASP.

ASP. NET Core Webapi Getting Started (iii) cross-domain processing

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.