title: HttpContext.Current null after async operation
body: <p>I'm having the same issue described in <a href="https://stackoverflow.com/q/18383923/2679750">this question</a> where I am losing <code>HttpContext.Current</code> after an async operation. The main difference between that question and mine, is that I've applied all of the possible solutions to resolve it - which all work <em>on my PC</em> but don't work when we deploy to the webserver, which has .NET 4.8 installed. Another thing to note is that when we apply the settings - we can see that the <code>SynchronizationContext</code> is of type <code>AspNetSynchronizationContext</code> (and not Legacy, so we seem to have what we want).</p>
  <p>We checked IIS App Settings and made sure there were no manually added or negating settings (like <code>&lt;add key=&quot;aspnet:UseTaskFriendlySynchronizationContext&quot; value=&quot;false&quot; /&gt;</code> or something similar) and there weren't. We also tried <code>&lt;httpRuntime targetFramework=&quot;4.5&quot; /&gt;</code> - which did not work.</p>
  <p>Are there any other settings/configurations/possible .NET CLR explanations that would make this setting: <code>&lt;add key=&quot;aspnet:UseTaskFriendlySynchronizationContext&quot; value=&quot;true&quot; /&gt;</code> not pass the HttpContext.Current to a thread while performing async operations?</p>
  <p>Also - if I have <code>&lt;httpRuntime targetFramework=&quot;4.5&quot; /&gt;</code> - and I see a <code>LegacyAspNetSynchronizationContext</code> - what could be the root cause?</p>
  <p>Example (locally) that works, but breaks on the webserver:</p>
  <pre><code>[HttpGet]
  [Route(&quot;api/DelayTest&quot;)]
  public async Task&lt;int&gt; Test()
  {
      var ctx = System.Web.HttpContext.Current; // not null
      await Task.Delay(new TimeSpan(0, 0, 5));
      ctx = HttpContext.Current; //null here (which causes issues)
          
      return 0;
  }
  </code></pre>
  <p>Note: We are targeting .NET 4.5:</p>
  <pre><code>&lt;compilation debug=&quot;true&quot; targetFramework=&quot;4.5&quot; /&gt;
  &lt;httpRuntime targetFramework=&quot;4.5&quot; maxQueryStringLength=&quot;6000&quot; /&gt;
  </code></pre>