2017-02-18 135 views
4

取得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

錯誤只發生在,它正常工作在其他瀏覽器。 我的本地主機上沒有發生錯誤,它只發生在主服務器上。

如果有人能夠解釋這個問題的解決方案,這將是非常有益的。

回答

0

我有同樣的問題,這發生在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(); 
相關問題