我想知道有没有人知道这个。
我在我的 asp.net vb 网络应用程序上遇到了一个非常严重的错误。我告诉你,我的额头上差点被 qwerty 染上了颜色,因为我的头撞在了键盘上。但我想我找出了错误的原因:
我有以下代码:
fileToDownload = createFileSet(fileToDownload, confirm)
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileToDownload.Name)
HttpContext.Current.Response.AddHeader("Content-Length", fileToDownload.Length.ToString())
HttpContext.Current.Response.ContentType = ReturnExtension(fileToDownload.Extension.ToLower())
HttpContext.Current.Response.TransmitFile(fileToDownload.FullName)
HttpContext.Current.ApplicationInstance.CompleteRequest()
Directory.Delete("C:\temp_" & confirm, True)
'System.IO.File.Delete(fileToDownload.FullName) <--- Error here
当我把最后一行的注释打勾时,我得到了一个非常丑陋的错误(我可以重做它并把它拼出来,什么样的错误,但这并不重要)。
我想我知道原因。用户正在下载文件,或正在下载文件,或其他内容,并且程序正在尝试删除它......导致错误。
有没有办法创建一些on HttpContext.Current.Response.TransmitFile.complete
(代码组成),还是我求助于批处理文件和 Windows 调度程序来清理这些不再需要的文件?
你认为我的错误结论正确吗?我真的看不到创建“活动”的方法,但我在 asp.net 上太新了,无法确定。