我的 ASP.NET Web API 中有以下任务,它将传入的请求保存为文件。它似乎在我的本地工作正常,但在托管服务器上,文件未保存,我的日志显示状态为故障。
据我了解,这与未处理的异常有关。我怎样才能找出这些异常是什么以便解决它们?
// 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());