Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting CORS error instead of 429 (when using AspNetCoreRateLimit Nuget) #450

Open
AssafKoh opened this issue Aug 9, 2023 · 1 comment

Comments

@AssafKoh
Copy link

AssafKoh commented Aug 9, 2023

Hello,

I started using your Nuget: "AspNetCoreRateLimit", which controls the maximum number of requests to a certain API or to all APIs.

After the desired number of requests, the API is indeed blocked.
for 3 requests I indeed see 429 as response status, but after the 3rd request and so on, I stop getting a 429 status and start getting a CORS error.

Do you have any idea why this is happening?

@ZhiFengCode
Copy link

ZhiFengCode commented Aug 27, 2024

Hello!

To resolve the CORS issue you're experiencing after hitting the rate limit, you can try applying the CORS middleware globally before the rate-limiting middleware. Here’s how you can configure it:

// Apply CORS globally before any other middleware
app.UseCors("AllowAllOrigins");

// Apply the rate limiting middleware
app.UseIpRateLimiting();

app.UseRouting();

// ...

This approach ensures that even when a 429 status code is returned, the CORS headers are correctly included. However, this is just my method—I’m not sure if it fits your scenario, but I hope it helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants