Monday, July 27, 2015

Cancel async requests in ASP.NET MVC

Starting from .NET 4.5 ASP.NET MVC supports async/await for the action methods on your controller:

Something I wasn’t aware of until I saw this blog post that is possible to cancel an async requests on the server. I knew it was possible to cancel an AJAX request on the client but I didn’t know that this cancellation will be forwarded to the server. I thought that on the server the request continued but that the result was discarded.

What you have to is to add a CancellationToken as an extra parameter to your action method:

No comments: