title: How to set ViewBag for _Layout in MVC4 using async in every action
body: <p>The usecase is simple. Info for logged in user is displayed in _Layout.cshtml. That info needs to be refreshed every time.</p>
  
  <p>I found two ways to do that</p>
  
  <ul>
  <li>Have <code>BaseController</code> and in its <code>OnActionExecuting</code> method set <code>ViewBag.UserInfo = ...;</code> which is later used in _Layout.cshtml</li>
  <li>In <code>_Layout.cshtml</code> do <code>@{Html.RenderAction("GlobalUserInfo", "UserInfo");}</code></li>
  </ul>
  
  <p>The problem is that these two ways fail miserably with deadlocks or exceptions if UserInfo is returned from an async <code>public async Task&lt;UserInfo&gt;GetUserInfo(){...}</code> method.</p>
  
  <p>So the question is this: How to set ViewBag properties on every action when data is retrieved using async/await.</p>