使用Asynchronous OnActionExecuting时:异步模块或处理程序在异步操作仍处于挂起状态时完成

问题描述 投票:0回答:1

我有一个控制器,其OnActionExecuting被重写为异步方法,这种方式:

protected override async void OnActionExecuting(ActionExecutingContext filterContext)
{
}

在该方法内部,我正在调用一些等待的方法,例如await db.Empresa.FindAsync(EmpresaID);await UserManager.FindByIdAsync(User.Identity.GetUserId());

因此,我收到错误:ASP.NET Controller: An asynchronous module or handler completed while an asynchronous operation was still pending

是否可以将OnActionExecuting方法设为异步?有没有办法解决这个问题?

Jaime

c# asynchronous async-await asp.net-mvc-5.2
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.