In an ApiController
操作 我需要在操作完成执行后立即关闭与数据库的连接。
在控制器下我重写OnActionExecuted
来实现这一目标。
我将如何在ApiController
action?
Thanks
你可以覆盖ExecuteAsync http://msdn.microsoft.com/en-us/library/system.web.http.apicontroller%28v=vs.108%29.aspx 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;
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)