【问题标题】:Failed - network error when downloading zip file made by Ionic.Zip.dll失败 - 下载 Ionic.Zip.dll 制作的 zip 文件时出现网络错误
【发布时间】:2017-07-07 21:31:14
【问题描述】:

我尝试从这样的 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();

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

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

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

【问题讨论】:

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


    【解决方案1】:

    我有同样的问题,这发生在 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();
    

    【讨论】:

    • IDK 当你被否决时。你的答案是正确的。这一行是我汇总所有文件大小的地方。 Response.AddHeader("Content-Length", longAllFileSizes.ToString());
    猜你喜欢
    • 1970-01-01
    • 2017-07-08
    • 2021-09-17
    • 2021-04-09
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多