2009-04-21 46 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);