title: Async method call and impersonation
body: <p>Why impersonation user context is available only until the async method call?
  I have written some code (actually based on Web API) to check the behavior  of the impersonated user context. </p>
  
  <pre><code>async Task&lt;string&gt; Test()
  {
      var context = ((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate();
      await Task.Delay(1);
      var name = WindowsIdentity.GetCurrent().Name;
      context.Dispose();
      return name;
  }
  </code></pre>
  
  <p>To my surprise in this situation I will receive the name of the App pool user. under which the code is running. That means that I don't have the imprsonated user context anymore. If the delay is changed to 0, which makes the call synchronous:</p>
  
  <pre><code>async Task&lt;string&gt; Test()
  {
      var context = ((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate();
      await Task.Delay(0);
      var name = WindowsIdentity.GetCurrent().Name;
      context.Dispose();
      return name;
  }
  </code></pre>
  
  <p>Code  will return the name of currently impersonated user. 
  As far as I understand the await and what debugger shows as well, the context.Dispose() is not called until name is being assigned. </p>