我尝试从 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();
但是我得到了这样的失败 - 网络错误
:
错误仅在 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/