4

我继承了一个旧应用程序,该应用程序将 zip 文件存储在数据库中,需要检索该文件。在 Firefox 中工作正常,我可以打开 zip 并且其中的每个文件都很好。当我在 IE7 中运行它时,出现以下错误。

Internet Explorer 无法从 localhost 下载 ProductContentFormImage.aspx。

Internet Explorer 无法打开此 Internet 站点。请求的站点不可用或找不到。请稍后再试。

我正在使用下面的代码。

byte[] content = (byte[])Session["contentBinary"];

Response.ClearContent();
Response.ClearHeaders();
Response.Clear();

Response.Buffer = true;
Response.Expires = 0;
Response.ContentType = "application/zip";
Response.AddHeader("Content-Length", content.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=content.zip");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(content);
Response.End();
4

2 回答 2

6

这是 IE 特有的一个奇怪的小错误。

基本上,当您将到期时间设置为 0 时,问题就会出现。

IE基本上经过以下过程:

  1. IE 确定文件是要“下载”的东西,这会导致 IE 打开文件下载弹出窗口。

  2. 一旦用户单击“打开”或“保存”,IE 就会尝试下载文件,但由于它被设置为立即过期,IE 就会出错。

将您的到期时间设置为一个小的非零数字,例如 1 分钟,您应该会看到问题消失。

于 2009-04-21T21:46:46.463 回答
1

我发现将 HttpCacheability 设置为 private 可以解决问题

context.Response.Cache.SetCacheability(HttpCacheability.Private);
于 2010-08-16T05:27:28.663 回答