2012-03-12 16 views
2

我有一個動態的PDF表單,該表單已填充並展平。 此PDF可以在任何版本的IE上正確顯示。 與Firefox我得到這個錯誤:使用iTextSharp PDF和Firefox獲取損壞的內容錯誤:不適用於Firefox 10.xx

Corrupted Content Error

The page you are trying to view cannot be shown because an error in the data transmission was detected.

The page you are trying to view cannot be shown because an error in the data transmission was detected. Please contact the website owners to inform them of this problem.

任何人都可以請幫我,爲什麼我收到此錯誤,什麼修復需要是沒有打破我的功能IE PDF的代碼。

+0

不能準確記得次要版本,但是我在自動更新之一上遇到同樣的問題。我認爲更新搞砸了PDF應用程序映射。必須手動重新添加映射才能打開PDFw/Adob​​e Reader。另一件有效的工作是添加「Content-Disposition」標頭,將PDF標記爲文件附件,但不確定是否要去那裏...... – kuujinbo 2012-03-12 18:50:24

+0

服務器發送的HTTP頭是什麼樣的? – 2012-03-12 22:47:40

+0

這是如何將PDF輸出到瀏覽器。 private void writeOutputStream(MemoryStream stream) //使用(MemoryStream stream = GeneratePDF(m_FormsPath,oXmlData)) // { byte [] bytes = stream.ToArray(); Response.ContentType =「application/pdf」; Response.BinaryWrite(bytes); Response.End(); //} } – djoshi 2012-03-13 13:44:38

回答

4

我有同樣的問題。在Firefox 11.0中,我會得到「損壞的內容錯誤」,但它會在其他瀏覽器中提供PDF。

問題很簡單,我已經在我的代碼中設置了Content-Disposition標頭兩次。 Firefox顯然對此很挑剔(或者最近變得如此)。一旦我擺脫了重複標題設置,它工作正常。

+0

非常感謝。這是問題所在。 – 2012-06-29 08:30:45

+0

是的,這是正確的。特別是在MVC中,這一點很重要,因爲MVC本身會在返回FileContentResult時自動設置Content-Disposition。 – James 2013-06-06 13:42:45

+0

有沒有辦法讓MVC不這樣做?我想將content-disposition指定爲inline,但是仍然遇到這個重複的頭錯誤。它似乎默認爲附件。 – Kris 2015-07-16 15:36:30

0

通過在上次使用AddHeader方法之前添加此項將提供解決方案。

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