---
title: "What is CORS and why do I keep getting a CORS error?"  
description: "What is CORS and why do I keep getting a CORS error?"  
author: "Kacper Jankowski"  
published: 2026-11-13  
updated: 2026-11-13  
canonical: https://www.mindstick.com/forum/163018/what-is-cors-and-why-do-i-keep-getting-a-cors-error  
category: "JavaScript and Frontend"  
tags: ["CORS", "browser security", "same-origin policy", "asp.net core", "web api"]  
reading_time: 1 minute  

---

# What is CORS and why do I keep getting a CORS error?

My React app on localhost:3000 calls my API on localhost:5000 and the browser blocks it with a CORS error. Is my API broken?

## Replies

### Reply by Saba Awan

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.


---

Original Source: https://www.mindstick.com/forum/163018/what-is-cors-and-why-do-i-keep-getting-a-cors-error

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
