Leo*_*Leo 4 asp.net-web-api asp.net-apicontroller
在ApiController动作中,我需要在动作执行完毕后立即关闭与数据库的连接.
在控制器下我覆盖OnActionExecuted以实现此目的.
如何在ApiController行动中实现这一目标?
谢谢
您可以覆盖该ExecuteAsync方法:
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;
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3320 次 |
| 最近记录: |