c# - 失败 - 下载由 Ionic.Zip.dll 制作的 zip 文件时出现网络错误

标签 c# asp.net iis zip ionic-zip

我尝试从 asp.net c# web 表单应用程序下载由 Ionic.Zip.dll 制作的 zip 文件,如下所示:

zip.AddEntry("filename", arraybyte);
Response.Clear();
Response.BufferOutput = false;
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=SuppliersDocuments.zip");
zip.Save(Response.OutputStream);
Response.Close();

但是我得到了这样的失败 - 网络错误:

enter image description here

错误仅在 chrome 中出现,在其他浏览器中可以正常运行。 错误不会发生在我的本地主机上,它只会发生在主服务器上。

如果有人能解释这个问题的解决方案,那将非常有帮助。

最佳答案

我有同样的问题,这发生在 Chrome 中。此问题发生在 Chrome v53 及更高版本上,解释为 here .

为了克服这个问题,我建议您获取文件的长度并在 header 中使用 Content-Length 并传递文件的长度。

string fileName = string.Format("Download.zip");
Response.BufferOutput = false;  // for large files  
using (ZipFile zip = new ZipFile())
{
      zip.AddFile(path, "Download");
      Response.Clear();
      Response.Buffer = true;
      Response.ContentType = "application/zip";
      Response.AddHeader(name: "Content-Disposition", value: "attachment;filename=" + fileName);
      Int64 fileSizeInBytes = new FileInfo(path).Length;
      Response.AddHeader("Content-Length", fileSizeInBytes.ToString());                                    
      zip.Save(Response.OutputStream);
      Response.Flush();
}
Response.Close();

关于c# - 失败 - 下载由 Ionic.Zip.dll 制作的 zip 文件时出现网络错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42313464/

相关文章:

asp.net - 如何处理 'The source contains no DataRows. ' 错误

asp.net - 在 ASP.Net Web 应用程序中运行后台任务并获取反馈的最佳方式?

asp.net - 无法使用 dotMemory 启动内存分析

c# - StringBuilder.Append 问题

c# - 在 Entity Framework 中使用带参数的存储过程

c# - 在 MEF 中不使用 ImportAttribute 或 ImportManyAttribute 获取导出的元数据?

c# - 标准化文件夹中的文件名

asp.net - 我需要下载 Microsoft Internet Information Services 吗?

python - 如何在 Microsoft Azure 上使用 web.py 提供静态内容?

c# - 将属性注册为 DependencyProperty