2012-03-12 19 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();