ASP MVC Core Cors Problem


Nowadays the applications are at the backend and single-page applications are working like forklift between the client and the back-end. These applications are like Angular or React. This trend caused a headache called the CORS error.

CORS originally is a security measure and it is a built-in feature in Google Chrome. This way, nobody can send fake requests to the server with single JavaScript.

To enable CORS on your ASP MVC Core project please visit the Configure section of the Startup.cs and add the below line.

app.UseCors(builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().AllowCredentials());

Normally using AllowAnyOrigin and AllowCredentials is not a best practice but it won’t create any obstacle on the way. You can edit it on your behalf.

Another Temporary Solution

You can press Win+R and run the Chrome browser without CORS patch activated.

chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security