Search code examples
asp.net-corevisual-studio-mac

ASP.NET Core 3.1 CORS error in VS for Mac


Initially, I started to develop my project on PC and now I'm trying to run it on Mac. When my front end tries to reach my web API endpoint, I'm getting the following error:

Failed to load resource: Origin https://localhost:3000 is not allowed by Access-Control-Allow-Origin

The thing is that it works perfectly on Windows, but doesn't work on Mac.

My code to enable CORS:

builder.UseCors(x => x
                .WithOrigins(new string[] { "https://localhost:3000" })
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowCredentials());

How to solve this issue?


Solution

  • Okay, it turned out that I had to "trust" the dev certificate created by dotnet core command. I opened my backend URL from browser (https://localhost:44372), clicked "Proceed" when the "site is unsafe" prompt appeared and only after that my front end (https://localhost:3000) was able to reach it.