Diagram showing cancellation token propagation flow from browser through ASP.NET Core to database

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 6, 2025 · 12 min · 2394 words · Abhinaw