Your API is probably fine. CORS (Cross-Origin Resource Sharing) is a browser protection. By default, a page from one origin (scheme + host + port) is not allowed to read responses from another origin. localhost:3000 and localhost:5000 are different origins.
The server must opt in by sending headers such as Access-Control-Allow-Origin. For non-simple requests (for example with a JSON body or an Authorization header) the browser first sends an OPTIONS "preflight" request, and the server must answer it correctly.
In ASP.NET Core:
builder.Services.AddCors(o => o.AddPolicy("web", p =>
p.WithOrigins("http://localhost:3000").AllowAnyHeader().AllowAnyMethod()));
app.UseCors("web");
Call UseCors before authorization and endpoints.
Avoid AllowAnyOrigin with credentials, and do not "fix" it by disabling browser security. CORS is not an API protection by itself; it does not stop other clients such as curl.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Your API is probably fine. CORS (Cross-Origin Resource Sharing) is a browser protection. By default, a page from one origin (scheme + host + port) is not allowed to read responses from another origin. localhost:3000 and localhost:5000 are different origins.
The server must opt in by sending headers such as
Access-Control-Allow-Origin. For non-simple requests (for example with a JSON body or an Authorization header) the browser first sends an OPTIONS "preflight" request, and the server must answer it correctly.In ASP.NET Core:
Call UseCors before authorization and endpoints.
Avoid
AllowAnyOriginwith credentials, and do not "fix" it by disabling browser security. CORS is not an API protection by itself; it does not stop other clients such as curl.