Asp.net 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. Asp.net 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 asp.net 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)