2009-04-21 43 views
3

我已经继承了一个旧的应用程序,它将压缩文件存储在数据库中,并且需要检索该文件。在Firefox中工作正常,我可以打开zip文件,里面的每个文件都很好。当我在IE7中运行它时,出现以下错误。写出一个压缩文件在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(); 

回答

6

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

基本上,这个问题提出了自己当您设置到期为0

IE基本上经过以下过程:

  1. IE确定该文件是值得被“下载”,这会导致IE打开文件下载弹出窗口。

  2. 一旦用户点击“打开”或“保存”,IE会尝试下载文件,但由于设置为立即过期,因此IE会跳出。

将您的到期时间设置为1分钟之类的非零数字,您应该看到问题消失。

1

我发现,设置HttpCacheability私人修复该问题

context.Response.Cache.SetCacheability(HttpCacheability.Private);