Handling Request Cancellation in ASP.NET Core: From Browser to Database

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: July 31, 2025 · 13 min

Custom Route Constraints in ASP.NET Core: Because Regex Isn’t Enough

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: July 24, 2025 · 8 min
×