title: MultipartFormDataStreamProvider and preserving current HttpContext
body: <p>I have a problem with the async file uploading feature of WebApi.</p>
  
  <p>Currently I am able to save the file using the provider, but I then want to use a service (_myService) to log the filename of the file uploaded.  Inside the service, it uses another service to get the current UserId.  It does this by using the current HttpContext. Unfortunately the current HttpContext seems to be lost within the new task thread.</p>
  
  <p>I tried to add TaskScheduler.FromCurrentSynchronizationContext() as the 2nd parameter of the task but this had no effect. Not really sure what that gives me. So I need some way of getting the Http context across to the new thread. How would I achieve this?</p>
  
  <pre><code>[ValidationFilter]
          public Task&lt;FileUpModel&gt; Upload([FromUri]int ReportType, [FromUri]string LocationDescription, string AdditionalInformation)
          {
              if (Request.Content.IsMimeMultipartContent())
              {
                  var imagePath = HttpContext.Current.Server.MapPath("~/App_Data");
  
                  var provider = new MyFormDataStreamProvider(imagePath);
  
                  var task = Request.Content.ReadAsMultipartAsync(provider).ContinueWith(
                  t =&gt;
                  {
  
                      if (t.IsFaulted || t.IsCanceled)
                          throw new HttpResponseException(HttpStatusCode.InternalServerError);
  
                      var fileInfo = provider.FileData.FirstOrDefault();
                      if (fileInfo == null)
                          throw new HttpResponseException(HttpStatusCode.InternalServerError);
  
                      // httpContext is lost here...
                      _myService.LogUploadedFile(fileInfo.LocalFileName);
  
                      var uploadModel = new FileUpModel { success = true };
                      return uploadModel;
                  }, TaskScheduler.FromCurrentSynchronizationContext());
  
                  return task;
              }
              else
              {
                  throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted"));
              }            
          }
  </code></pre>