title: HttpContext.Current null inside async task
body: <p>I have a method that uses a repository (<code>userRepo</code>):</p>
  
  <pre><code>    public override Task&lt;IdentityResult&gt; CreateLocalUserAsync(IUser user, string password, CancellationToken cancellationToken)
      {
          var task = new Task&lt;IdentityResult&gt;(() =&gt; {
  
              TUserEntity newUser = new TUserEntity
              {
                  Id = user.Id,
                  UserName = user.UserName,
                  Password = password
              };
  
              userRepo.Save(newUser).Flush();
  
              return new IdentityResult(true);
          }, cancellationToken);
  
          task.Start();
  
          return task;
      }
  </code></pre>
  
  <p>The <code>userRepo</code>object has a dependency that uses <code>HttpContext.Current</code>.  Both of these are resolved using ninject <code>InRequestScope</code>.  </p>
  
  <p>The above method is called inside the default <code>AccountController</code> in Mvc 5:</p>
  
  <pre><code>var result = await IdentityManager.Users.CreateLocalUserAsync(user, model.Password);
  </code></pre>
  
  <p>I have tried adding this setting to web.config:</p>
  
  <pre><code>&lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /&gt;
  </code></pre>
  
  <p>Also, I am definitely using .NET 4.5.  This is also in my web.config:</p>
  
  <pre><code>&lt;httpRuntime targetFramework="4.5" /&gt;
  </code></pre>
  
  <p>It is not possible to get the information from the <code>HttpContext</code> before I start the task because a dependency of the <code>userRepo</code> in the task is using the information and both objects are resolved using Ninject.</p>
  
  <p>How can I ensure that <code>HttpContext.Current</code> will not be null?</p>