We want to display version detail from our back end services on the bottom of all pages.
The 3 backend services are async webapi(2.2) calls, we need to make these 3 async calls aggregate the date into a model and then pass that to the View.
If i do this as part of a (not-child) controller action the code works and displays the data.
However trying to display this data at the bottom of every page (child action) gives several differing async deadlock type conditions.
child action and call on _layout.cshtml
//ControllerAction
[ChildActionOnly]
public ActionResult VersionInfo()
{
var version = _versionInfoViewModelMapper.Map().Result;
return View(version);...
}
//Layout.cshtml
@if(Request.IsAuthenticated)
{
Html.RenderAction("VersionInfo", "Utils");
}
This results in what seems to be a deadlock as the request doesn't end,
using An ActionFilter
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
var viewBag = filterContext.Controller.ViewBag;
if (filterContext.RequestContext.HttpContext.Request.IsAuthenticated)
{
//viewBag.VersionInfo = Task.Run(() => _versionInfoViewModelMapper.Map()).Result;
viewBag.VersionInfo = _versionInfoViewModelMapper.Map().Result;
}
}
using the above filter to pass the data to the ViewBag which is then used, gives the same endless call.
If I don't use the .Result on the async calls i get an Error
HttpServerUtility.Execute blocked while waiting for an asynchronous operation to complete.
Is there a way i can get around this issue? potentially by using a Global.asax Application_PostAuthenticateRequest or similar event?