2
我在ASP.NET Web API中將以下任務保存爲文件。它似乎在我的本地工作正常,但在託管服務器上,該文件未保存,並且我的日誌顯示狀態爲Faulted。Task.Status.Faulted - 如何處理異常
據我所知,這與未處理的異常有關。我怎樣才能找出這些例外是什麼,以便我可以解決它們?
// Save file
MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(HttpContext.Current.Server.MapPath("~/Files"));
Task<IEnumerable<HttpContent>> task = Request.Content.ReadAsMultipartAsync(provider);
return task.ContinueWith<string>(contents =>
{
string filename = provider.BodyPartFileNames.First().Value;
FileInfo file = new FileInfo(filename);
Log.LogMessage("Status: " + task.Status.ToString() + " File Exists: " + file.Exists);
// Delete excel file when complete.
File.Delete(filename);
// Return message to user.
return "Complete";
}, TaskScheduler.FromCurrentSynchronizationContext());