C# 使用Ihttphandler下载多个文件
格雷廷斯 我正在编写一个报告脚本,它在点击按钮时运行许多报告(pdf)。报告是在web服务器上创建的,然后我希望用户可以选择下载文件。我已经制定了从服务器下载一个文件的脚本。但我不知道如何下载多个文件?(大概会有50人左右) 运行一个报告后,我将用户重定向到http处理程序脚本C# 使用Ihttphandler下载多个文件,c#,asp.net,ihttphandler,C#,Asp.net,Ihttphandler,格雷廷斯 我正在编写一个报告脚本,它在点击按钮时运行许多报告(pdf)。报告是在web服务器上创建的,然后我希望用户可以选择下载文件。我已经制定了从服务器下载一个文件的脚本。但我不知道如何下载多个文件?(大概会有50人左右) 运行一个报告后,我将用户重定向到http处理程序脚本 Response.Redirect("Download.ashx?ReportName=" + "WeeklySummary.pdf"); public class Download : IHttpHandler {
Response.Redirect("Download.ashx?ReportName=" + "WeeklySummary.pdf");
public class Download : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
StringBuilder sbSavePath = new StringBuilder();
sbSavePath.Append(DateTime.Now.Day);
sbSavePath.Append("-");
sbSavePath.Append(DateTime.Now.Month);
sbSavePath.Append("-");
sbSavePath.Append(DateTime.Now.Year);
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpResponse objResponce = context.Response;
String test = HttpContext.Current.Request.QueryString["ReportName"];
HttpContext.Current.Response.AppendHeader("content-disposition", "attachment; filename=" + test);
objResponce.WriteFile(context.Server.MapPath(@"Reports\" + sbSavePath + @"\" + test));
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.End();
}
public bool IsReusable { get { return false; } }
}
提前感谢您,如果您还想看我的脚本,请告诉我。我马上看到的两个选项显然是重复调用HTTP处理程序的选项。另一种方法是在服务器上对它们进行压缩,然后通过网络发送压缩文件。您可以使用内置类来实现这一点
此外,您还需要在处理程序中添加一些代码,以便在下载这些临时文件后对其进行清理。我曾考虑过多次调整HTTP Headler负载,但不确定是否有更好的方法。我想我会把拉链拉上。谢谢你的链接!