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

Rez*_*ini 5 c# asp.net iis zip ionic-zip

我尝试Ionic.Zip.dll从asp.net c#web表单应用程序下载一个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();
Run Code Online (Sandbox Code Playgroud)

但我Failed - network error这样:

在此输入图像描述

错误只发生在chrome中,它在其他浏览器中正常工作.我的localhost上不会发生错误,它只发生在主服务器上.

如果有人可以解释这个问题的解决方案将是非常有帮助的.

Adh*_*llo 1

我有同样的问题,并且这种情况发生在 Chrome 中。此问题发生在 Chrome v53 及更高版本上,对此进行了解释。

为了解决这个问题,我建议您获取文件的长度并在标头中使用 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();
Run Code Online (Sandbox Code Playgroud)