2012-01-03 20 views
0

我使用下面的代碼的PDF發送到瀏覽器Response.BinaryWrite沒有MAC的Safari工作

 Response.ClearContent(); 
     Response.ClearHeaders(); 
     Response.AddHeader("Content-Length", fileBytes.Length.ToString()); 
     Response.ContentType = "application/pdf"; 
     Response.BinaryWrite(fileBytes); 
     Response.Flush(); 
     System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest(); 

它運作良好(PDF正確嵌入在瀏覽器中)以外的Safari瀏覽器的所有(版本5.x)在MAC。此外,它適用於Mac和Firefox中的Firefox和Chrome。
我想知道它是一個瀏覽器問題?或者Response.BinaryWrite有問題?

[編輯]
Safari的行爲,pdf根本沒有加載。顯示一個進度條並繼續加載,可能與安裝的PDF插件有關?那麼,如何弄清楚爲什麼在Safari中這種行爲呢?

[編輯]
這個錯誤被記錄在Safari開發工具控制檯「無法加載資源:插件所處理的負載」,這似乎是它涉及到PDF插件。

+0

在Safari中會發生什麼? – ZippyV 2012-01-03 09:58:48

+0

PDF完全不加載?一個進度條在那裏?可能是該progree欄與安裝的Adobe插件有關。 – Ahmed 2012-01-03 10:01:02

+0

@ Ahmed:當進度條完成時會發生什麼?它在瀏覽器中打開pdf嗎? – 2012-01-03 10:19:46

回答

0

試試這個,它的工作我沒問題

 Response.ClearContent(); 
     Response.ClearHeaders(); 
     Response.ContentType = "application/pdf"; 
     Response.Buffer = true; 
     Response.AppendHeader("Accept-Header", attachmentObj.AttachmentFile.Length.ToString()); 
     Response.AppendHeader("content-disposition", "attachment; filename=\"" + HttpUtility.UrlEncode(attachmentObj.Description, System.Text.Encoding.UTF8) + "\""); 
     Response.AppendHeader("Pragma", "public"); 
     Response.BinaryWrite((byte[])attachmentObj.AttachmentFile.ToArray());   
     Response.Flush(); 
     Response.End(); 
+0

無法加載資源:加載頁面時,插件處理的加載錯誤仍然記錄在控制檯日誌中。 – Ahmed 2012-01-03 13:05:50

相關問題