I am trying to write a controller that receives a request from an AJAX call and performs some calls to the database via the DBContext. However, when I place the command var user = await GetCurrentUserAsynch();
in front of any calls to the DBContext, as shown below, I get an ObjectDisposedException (Cannot access a disposed object).
It appears to be the UserManager and the DBContext not playing nicely together, however I can't find much information on the matter.
[HttpPost]
public async void EditUserMapItemAjax([FromBody]UserMapItemViewModel userMapItemViewModel)
{
var user = await GetCurrentUserAsync();
var mapItem = _db.MapItems.SingleOrDefault(x => x.Id == userMapItemViewModel.MapItemId);
...
}
private Task<ApplicationUser> GetCurrentUserAsync() => _userManager.GetUserAsync(HttpContext.User);