Breaking

Thursday, June 3, 2021

ASP.NET Core - Handle cancelled requests

When an HTTP request is made to your ASP.NET Core application, it is always possible that the request is aborted. For instance when the user closes it browsers without waiting for the response. In this case, you may want to stop all the work to avoid consuming resources.

Here are 2 possible approaches on how to handle this scenario. A first option is to check the HttpContext.RequestAborted property:

 



A second option is to let the Modelbinder do it’s work and add a parameter of type CancellationToken to the action:

No comments:

Post a Comment