No Access-Control-Allow-Origin ),

Source: Internet
Author: User

No Access-Control-Allow-Origin ),

Preface:

Download ASP. the NET Core 2.x + Angular template project is independently deployed on the Web API and angular frontend in a ReStful architecture. After I deploy them separately in IIS, the front-end access API will generate cross-origin access restriction. By checking the Code, in fact, the TTL framework comes with cross-origin access settings, you only need to configure it, as shown in the following steps:

 

1. IIS deployment

Create a project using the template on the ABC official website, and then package the frontend and backend programs and release them to IIS:

My backend is released to: http: // localhost: 8060/

My front-end is released to: http: // localhost: 8080/

 

F12 error does not Allow cross-Origin access: Response to preflight request doesn't pass Access control check: No 'access-Control-Allow-origin' header is present on the requested resource. origin 'HTTP: // localhost: 100' is therefore not allowed access.

 

Ii. configuration instructions

Check that the Code has two configurations:

1. Configure the front-end in src/assets/appconfig. json

{  "remoteServiceBaseUrl": "http://localhost:8060",  "appBaseUrl": "http://localhost:8080"}

RemoteServiceBaseUrl

 

2. Configure the backend in the Host project appsettings. json

"App": {    "ServerRootAddress": "http://localhost:8060/",    "ClientRootAddress": "http://localhost:8080/",    "CorsOrigins": "http://localhost:8080/"  }

ClientRootAddress is configured for the client site,CorsOrigins is configured to allow cross-origin client sites, Multiple can be separated by commas, and configured in Startup. cs.

// Configure CORS for angular2 UIservices.AddCors(options =>{  options.AddPolicy(DefaultCorsPolicyName, builder =>    {       // App:CorsOrigins in appsettings.json can contain more than one address separated by comma.       builder       .WithOrigins(_appConfiguration["App:CorsOrigins"].Split(",", StringSplitOptions.RemoveEmptyEntries)       .Select(o => o.RemovePostFix("/"))       .ToArray())       .AllowAnyHeader()       .AllowAnyMethod();     });});

 

3. Run

Access to the client again after configuration is successful

 

 

Blog: http://www.cnblogs.com/donaldtdz/p/7882316.html if you want to deploy the front-end Integration together

 

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.