rate-limiting

Implement rate limiting in ASP.NET Core applications using built-in middleware and Redis.

Updated Mar 8, 2026
One-click install
npx skills add https://github.com/AGIBuild/dotnet.CI.template --skill rate-limiting-agibuild
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: rate-limiting
Source: https://github.com/AGIBuild/dotnet.CI.template/tree/main/.cursor/skills/rate-limiting
Command: npx skills add https://github.com/AGIBuild/dotnet.CI.template --skill rate-limiting-agibuild

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? ASP.NET Core applications without request throttling are vulnerable to abuse, traffic spikes, and cascading failures. This Skill provides production-ready patterns for protecting endpoints with fixed window, sliding window, token bucket, and distributed rate limiting. ## Core Features & Use Cases - Built-in Middleware Configuration: Set up Microsoft.AspNetCore.RateLimiting with global limiters, named policies, and custom 429 rejection responses. - Per-Endpoint and User-Based Policies: Apply different limits to login, API, and Razor Pages endpoints, including tier-based limits keyed by authenticated user identity. - Distributed Rate Limiting with Redis: Coordinate limits across multiple servers using atomic Lua scripts, with graceful fail-open degradation when Redis is unavailable. - Use Case: You are deploying a multi-instance API behind a load balancer and need login attempts capped at 5 per 5 minutes while general API calls allow 1000 per minute, tracked consistently across all servers. ## Quick Start Ask the AI to add rate limiting to your ASP.NET Core app with a strict login policy and a Redis-backed distributed limiter for API endpoints.

Frequently Asked Questions about rate-limiting

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add rate limiting to an ASP.NET Core application?▼

Register the built-in Microsoft.AspNetCore.RateLimiting middleware with AddRateLimiter in Program.cs, define global or named policies such as fixed window or token bucket, then call app.UseRateLimiter() after UseRouting and after authentication middleware.

How do I implement distributed rate limiting with Redis in .NET?▼

Use a Lua script executed via StackExchange.Redis that atomically increments a counter key and sets its expiry, returning whether the request is allowed plus the TTL for Retry-After. Wrap it in middleware that adds X-RateLimit headers and returns 429 when the limit is exceeded.

What is the difference between fixed window, sliding window, and token bucket rate limiters?▼

Fixed window allows a set number of permits per time window, sliding window divides the window into segments for smoother distribution, and token bucket replenishes tokens periodically to allow controlled bursts. Choose based on whether you need burst tolerance or strict uniformity.

Why does rate limiting not work correctly behind a load balancer?▼

The connection IP becomes the proxy address, so all clients share one partition. Configure ForwardedHeaders middleware and read the X-Forwarded-For or X-Real-IP header to identify the real client IP before partitioning.

What happens to rate limiting when Redis goes down?▼

Without handling, a Redis failure can break all requests. Wrap the limit check in a try-catch that logs the error and fails open by allowing the request, so the application degrades gracefully instead of rejecting traffic.