【发布时间】:2010-09-17 17:25:57
【问题描述】:
编辑 2
似乎在 Dom 中移动对象标签是问题的原因。我直接在页面上添加了一个 iframe,它工作正常,没有任何问题。
但是,当我将该 iFrame 移动到模式对话框 (http://www.ericmmartin.com/projects/simplemodal/) 中时,PDF 消失了(对象标签不再正确呈现)。
所以看来这不再是关于我的处理程序的问题,而是关于为什么在 DOM(位于 iFrame 内)中移动“对象”(或嵌入)标签会导致它“空白”的问题。 "
此外,当 pdf 从模态对话框移回其原始位置时,它会正确显示。所以,也许我应该更多地关注模态对话本身。
有什么想法?感谢您迄今为止的建议。
编辑 1
所以我为测试做了一些修改。
我有 iframe 来输出 pdf 请求的对象标记以及服务器时间。
Response.AddHeader("content-type", "text/html");
WebClient client = new WebClient();
Response.Write("<html><head></head><body><h1>"+ DateTime.Now.ToString() + "</h1><object height='100%' width='100%' name='plugin' data='" + Request.Url.ToString() + "&embed=true' type='application/pdf' /></body></html>");
Response.Flush();
Response.Close();
Response.End();
现在我正确地获得了当前时间的页面,但该对象仅在我发布 aspx 页面后第一次显示 PDF。所以这似乎是某种缓存问题?除了对象没有加载任何东西(甚至没有加载之前加载的 PDF)。
如果右键单击 iframe 并刷新页面,对象加载正常。 (如果我使用嵌入标签也是如此)。
原始问题
我知道这方面有很多问题......
- streaming PDF data through an ASPX page
- Server generated PDF not displaying in IFrame on aspx page on some (but not all )PCs
- Displaying a PDF Document in ASP.net page
但是他们要么没有得到答复,要么没有得到答复。
环境
- .Net 4
- Adobe 9.3.4
- IIS 5.1
- XP sp3
- VS 2010
- IE 8.0.6001.18702
背景
我正在流式传输的 pdf 来自文件没有任何扩展名的存储库(这样做是为了安全)。我在数据库中查找文件并通过以下代码将其流式传输回客户端:
Response.Clear();
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(sPath);
Response.AddHeader("content-length", buffer.Length.ToString());
Response.AddHeader("content-disposition", "inline;filename=" + fileName);
Response.AddHeader("expires", "0");
Response.AddHeader("Content-Type", "application/pdf"); //this is usually dynamic to support other types (doc, xls, txt, etc.)
Response.OutputStream.Write(buffer, 0, buffer.Length);
Response.Flush();
Response.Close();
Response.End();
这适用于在浏览器或 iframe(显示为模式弹出窗口)中直接使用的每种文件类型(doc、txt、xls、html),pdf 的exception 文件。通过 iframe 访问时它们不能可靠地工作,但在浏览器中直接访问时工作正常。
它唯一起作用的时候是我在发布提供这些文件的 aspx 页面后第一次请求文档。所有后续点击都会返回一个空白页面(即使来自新选项卡或浏览器窗口)。 无论如何,Firefox 每次都能可靠地显示 pdf。
尝试的解决方案
我尝试了各种流式传输文件的方法:
Response.TransmitFile(sPath);
Response.WriteFile(sPath);
//As well as some others
我尝试在请求结束时将 .pdf 添加到参数中
http://www.myurl.aspx?File=test.pdf
我尝试通过添加时间戳使 URL 独一无二
http://www.myurl.aspx?File=test.pdf&Unique=Friday__September_17__2010_12_02_16_PM
未尝试
我读过有关 IIS 压缩会导致问题的信息,但它是针对较新版本的 IIS。
没有尝试使用嵌入标签,因为我想尽可能坚持使用 iFrame(现有基础设施使用它)。
任何帮助将不胜感激!!!
谢谢。
【问题讨论】:
标签: c# internet-explorer pdf iframe simplemodal