APIController Done Method?

In the ApiController action ApiController I need to close the database connection as soon as the action completes.

Under the controller, I override OnActionExecuted to accomplish this.

How can I accomplish this with an ApiController action?

thanks

+4
source share
1 answer

You can override the ExecuteAsync method:

 public override Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken) { return base .ExecuteAsync(controllerContext, cancellationToken) .ContinueWith(t => { // the controller action has finished executing, // your custom code could come here ... return t.Result; }); } 
+6
source

Source: https://habr.com/ru/post/1489291/


All Articles