I discovered a work around in the end, it doesn't look as clean as I would have liked. Basically, I keep a copy of the context in a separate variable and pass this into the closure. Not sure if this is best practise or not but it works!
var currentHttpContext = HttpContext.Current;
var task = Request.Content.ReadAsMultipartAsync(provider).ContinueWith(
t =>
{
// Enquiry service requires access to authentication data which is retrieved via http context.
// Not ideal but set the http context here so it available on the new thread.
HttpContext.Current = currentHttpContext;
if (t.IsFaulted || t.IsCanceled)
throw new HttpResponseException(HttpStatusCode.InternalServerError);
var fileInfo = provider.FileData.FirstOrDefault();
if (fileInfo == null)
throw new HttpResponseException(HttpStatusCode.InternalServerError);
_myService.LogUploadedFile(fileInfo.LocalFileName);
var uploadModel = new FileUpModel { success = true };
return uploadModel;
});
return task;