【发布时间】:2023-03-25 11:35:01
【问题描述】:
我的代码是这样的
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + "name" + ".pdf");
HttpContext.Current.Response.TransmitFile("~/media/pdf/name.pdf");
HttpContext.Current.Response.End();
if (FileExists("/media/pdf/name.pdf"))
{
System.IO.File.Delete("D:/Projects/09-05-2013/httpdocs/media/pdf/name.pdf");
}
这里我想在浏览器中下载name.pdf,下载后我想删除那个文件。但是代码执行停止在
HttpContext.Current.Response.End();
该行执行后没有代码。所以我的删除功能不起作用。有没有解决这个问题的方法?
【问题讨论】:
-
把这段代码 HttpContext.Current.Response.End();在 Delte() 之后。 Response.End() 将停止asp.net中的Page Life cycel Execution
-
@AKS 什么后台工作者?
-
@nmat :这是对另一条评论的回复。我想他已经删除了它
-
@AkshayJoy 已经尝试过了。但是在那之后下载不会发生。因为文件不存在
-
@AKS 请检查此stackoverflow.com/questions/736301/…