core webapi server configuration cross-origin, corewebapi

Source: Internet
Author: User core webapi server configuration cross-origin, corewebapi

In the frontend and backend separation development, the server only provides api interfaces for the frontend, And the frontend and backend are usually deployed separately. In this case, cross-origin browser issues may occur. core provides simple and elegant solutions.

Add the following code to Configure in the startup File (replace "http: // localhost: 8080" with your frontend deployment address. The frontend address tested here is the local port 8080)

Note: The nuget package must be installed below core2.0: Microsoft. AspNetCore. Cors

App. UseCors (builder ==>{ builder. AllowAnyHeader (); builder. AllowAnyMethod (); builder. WithOrigins ("http: // localhost: 8080 ");});

If you only need to replace builder in the development environment. withOrigins ("http: // localhost: 8080") is builder. allowAnyOrigins () allows cross-origin access from any source address (not recommended in the production environment)

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: 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.