Introduction
When you build a modern ASP.NET Core 10 Web API, one of the most important things to think about is how to protect your API from too many requests. If a large number of users, bots, or automated scripts start sending requests at the same time, your server can slow down, consume too many resources, or even stop working.
This is where rate limiting in ASP.NET Core 10 becomes very useful.
Rate limiting helps you control how many requests a client (user, browser, or system) can send to your API within a specific time period. The good news is that ASP.NET Core 10 provides built-in rate limiting middleware, so you do not need any third-party libraries.
In this detailed guide, you will learn how to implement rate limiting in ASP.NET Core 10 step by step using simple language, real examples, and best practices.
What is Rate Limiting?
Rate limiting is a technique used in API development to control how frequently a client can access your API.
In simple words, it means:
You define a limit (for example, 5 requests)
You define a time period (for example, 10 seconds)
If the client exceeds this limit, further requests are temporarily blocked
For example:
A user can call your API only 10 times per minute
After that, the API will return an error (HTTP 429 - Too Many Requests)
This concept is very important for API security, performance optimization, and scalability in ASP.NET Core applications.
Why Use Built-in Rate Limiting in ASP.NET Core 10?
ASP.NET Core 10 includes a powerful built-in rate limiting system that is easy to configure and highly efficient.
Here are some strong reasons to use it:
No third-party dependency: You do not need external NuGet packages
Better performance: Optimized by Microsoft for high-speed APIs
Simple configuration: Easy to set up in Program.cs
Multiple strategies supported: Fixed window, sliding window, token bucket, concurrency limiter
Production-ready: Suitable for real-world scalable APIs
Using built-in rate limiting also helps improve API reliability, backend stability, and user experience.
Step 1: Create a New ASP.NET Core 10 Web API Project
First, create a new ASP.NET Core Web API project using the .NET CLI.
dotnet new webapi -n RateLimitingDemo
cd RateLimitingDemo
This command creates a ready-to-use API project with basic configuration.
Step 2: Add Rate Limiting Services
Now, we need to register rate limiting services in the dependency injection container.
Open Program.cs and add the following configuration:
using System.Threading.RateLimiting;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRateLimiter(options =>
{
options.AddFixedWindowLimiter("fixed", opt =>
{
opt.PermitLimit = 5; // Maximum 5 requests
opt.Window = TimeSpan.FromSeconds(10); // per 10 seconds
opt.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
opt.QueueLimit = 2;
});
});
Explanation (in simple words)
PermitLimit = 5→ Only 5 requests are allowedWindow = 10 seconds→ Time duration for those requestsQueueLimit = 2→ Extra requests will wait in queue (max 2)OldestFirst→ Older requests are processed first
This configuration is ideal for basic API rate limiting in ASP.NET Core 10.
Step 3: Enable Rate Limiting Middleware
After configuring services, you need to enable the rate limiting middleware in the HTTP pipeline.
var app = builder.Build();
app.UseRateLimiter();
app.MapGet("/", () => "Hello World!")
.RequireRateLimiting("fixed");
app.Run();
Explanation
UseRateLimiter()activates rate limitingRequireRateLimiting("fixed")applies the policy to the endpoint
Now your API endpoint is protected with rate limiting.

Join the conversation! Your thoughts help the community grow.