ASP.NET Core Request Limits with IP and MemoryCache

Protect your ASP.NET Core APIs from abuse with custom request throttling middleware using IMemoryCache and per-IP limits. Learn to implement, configure, and monitor rate limiting for robust, high-performance APIs.

July 2, 2025 · Last modified: September 20, 2025 · 10 min

Understanding dotnet dev-certs https: Local HTTPS for .NET Development

Master local HTTPS in .NET with dotnet dev-certs https. Learn how to create, trust, and troubleshoot development certificates, avoid common pitfalls, and follow best practices for secure, productive local development.

July 1, 2025 · 6 min

DRY API Responses in ASP.NET Core

TL;DR Avoid repetitive response handling in ASP.NET Core controllers by using helper methods or result wrapper patterns. Helper methods reduce boilerplate for common responses like BadRequest, NotFound, and Ok. The result wrapper pattern centralizes success and error handling, making controllers cleaner and responses consistent. Keep business logic in services and HTTP response logic in controllers for better separation of concerns. Use extension methods and middleware for standardized error handling and global exception management. Consistent response patterns improve API documentation and client experience. Minimal performance impact; benefits in maintainability and clarity far outweigh the overhead. We’ve all been there. You’re building an API and you find yourself writing the same code over and over again: ...

June 26, 2025 · Last modified: September 20, 2025 · 5 min
Diagram showing HTTP request and response flow through custom logging middleware with stream capturing and rewinding techniques

Request & Response Body Logging in ASP.NET Core

TL;DR Use custom middleware to log HTTP request and response bodies in ASP.NET Core for better debugging and diagnostics. Implement stream rewinding to read request bodies without breaking downstream middleware. Always redact sensitive data and use selective logging to avoid performance and security issues. Handle large bodies by truncating logs and excluding static or health check endpoints. Consider built-in HttpLogging for simple scenarios, but use custom middleware for full control and compliance. We’ve all been there, stuck debugging an API issue for hours, wishing we could just see what’s actually coming in and going out of our application. That’s exactly what request and response body logging solves. ...

June 25, 2025 · Last modified: September 20, 2025 · 13 min

Handle Request Cancellation in ASP.NET Core

TL;DR: ASP.NET Core cancels requests when the client disconnects or times out. Use HttpContext.RequestAborted and pass it through to services and EF Core/database calls. Proper cancellation avoids wasted CPU, memory leaks, and long-running queries. Always propagate the cancellation token from controller to database for graceful shutdown. Ever clicked the stop button while waiting for a web page to load? What actually happens on the server when you do that? ...

June 22, 2025 · Last modified: September 19, 2025 · 13 min

Enhance ASP.NET Core Routes with Custom Constraints

TL;DR Learn how to build custom route constraints in ASP.NET Core using IRouteConstraint. Use them to validate route parameters (like ensuring only alphabets or specific patterns), inject services like IUserService, and simplify controller logic. Bonus: works with minimal APIs, conventional routes, and supports DI in constraints via the new ASP.NET Core routing system. URL routing is a fundamental part of ASP.NET Core applications, determining how incoming requests are mapped to controller actions. While the framework provides numerous built-in route constraints like int, bool, and guid, there are situations where you need more sophisticated validation rules for your URL parameters. This is where custom route constraints become invaluable. ...

June 20, 2025 · Last modified: September 20, 2025 · 8 min
×