APIController"执行的"方法? [英] APIController "Executed" method?
本文介绍了APIController"执行的"方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在一个 ApiController
行动,我需要尽快关闭与数据库的连接作为操作执行完毕。
In an ApiController
action I need to close a connection to a database as soon as the action is finished executing.
在控制器我重写 OnActionExecuted
来做到这一点。
Under a controller I override OnActionExecuted
to accomplish this.
我将如何做到这一点的 ApiController
作用下?
How would I accomplish this under an ApiController
action?
感谢
推荐答案
您可以覆盖的 ExecuteAsync
方式:
You could 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;
});
}
这篇关于APIController&QUOT;执行的&QUOT;方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文