失败 - 网络错误下载由Ionic.Zip.dll

失败 - 网络错误下载由Ionic.Zip.dll

问题描述:

取得zip文件,当我尝试下载由Ionic.Zip.dll从一个asp.net C#Web表单应用程序作出这样一个zip文件:失败 - 网络错误下载由Ionic.Zip.dll

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(); 

,但我得到Failed - network error这样的:

enter image description here

错误只发生在,它正常工作在其他浏览器。 我的本地主机上没有发生错误,它只发生在主服务器上。

如果有人能够解释这个问题的解决方案,这将是非常有益的。

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

为了克服这个问题,我建议你获取文件的长度并在头文件中使用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();