C# 模态iframe中的PDF在IE中呈现为空白

C# 模态iframe中的PDF在IE中呈现为空白,c#,internet-explorer,pdf,iframe,simplemodal,C#,Internet Explorer,Pdf,Iframe,Simplemodal,编辑2 似乎在Dom中移动对象标记是问题的原因。我直接在页面中添加了一个iframe,它运行良好,没有任何问题 但是,当我将iFrame移动到模式对话框()中时,PDF消失(对象标记不再正确呈现) 因此,这似乎不再是关于我的处理程序的问题,而是关于为什么在DOM(位于iFrame内部)中移动“object”(或embed)标记会导致它“空白”的问题 此外,当pdf从模式对话框移回其原始位置时,它会正确显示。所以,也许我应该更多地关注模态对话本身 想法?感谢您迄今为止的建议 编辑1 所以我对测试

编辑2

似乎在Dom中移动对象标记是问题的原因。我直接在页面中添加了一个iframe,它运行良好,没有任何问题

但是,当我将iFrame移动到模式对话框()中时,PDF消失(对象标记不再正确呈现)

因此,这似乎不再是关于我的处理程序的问题,而是关于为什么在DOM(位于iFrame内部)中移动“object”(或embed)标记会导致它“空白”的问题

此外,当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();
当直接在浏览器或iframe(显示为模式弹出窗口)中使用pdf文件的异常时,这适用于每种文件类型(doc、txt、xls、html)。当通过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(现有的基础设施使用它)

任何帮助都将不胜感激


谢谢。

当PDF通过SSL传输时,我遇到了一个类似的问题(即仅FF没有出现此问题),只有通过执行以下操作才能解决此问题:

Response.ClearHeaders();
Response.ClearContent();
Response.Buffer = true;

Response.AppendHeader("Content-Disposition", "inline; attachment; filename=Filename.pdf");
Response.ContentType = "application/pdf";

Response.WriteFile(path);

Response.Flush();
Response.End();

我不确定您是否需要设置文件名,尤其是如果它没有.pdf扩展名。过去,当将PDF流式传输到浏览器时,我总是使用以下代码:

Response.Clear();
Response.ContentType = "application/pdf";
Response.BinaryWrite(pdfBuffer);
Response.Flush();

否则,客户端计算机上的
应用程序/pdf
CLSID的注册表设置可能会出现问题。

因此我放弃了,决定使用标准的IE弹出窗口

window.open(URL, 'Window', 'height=' + pageHeight + ',width=' + pageWidth + ',top=0,left=0,resizable');
我必须在对象标记中呈现PDF,在弹出窗口中的iframe中呈现其他所有内容,才能使其工作,但它可以工作

if (sDocType == "pdf")
{
    Response.AddHeader("content-type", "text/html");
    WebClient client = new WebClient();
    Response.Write("<html style='margin:0px;padding:0px;'><head></head><body style='margin:0px;padding:0px;'><object height='100%' width='100%' name='plugin' data='" + Request.Url.ToString() + "&embed=true' type='" + zGetContentType(HttpContext.Current.Request.QueryString["docType"]) + "'><param name='src' value='" + Request.Url.ToString() + "&embed=true' />alt : <a href='" + Request.Url.ToString() + "&embed=true'>View</a></object></body></html>");
    Response.Flush();
    Response.Close();
    Response.End();
}
else
{
    Response.AddHeader("content-type", "text/html");
    WebClient client = new WebClient();
    Response.Write("<html style='margin:0px;padding:0px;'><head></head><body style='margin:0px;padding:0px;'><iframe frameborder='0' scrolling='no' height='100%' width='100%' src='" + Request.Url.ToString() + "&embed=true' /></body></html>");
    Response.Flush();
    Response.Close();
    Response.End();
}
if(sDocType==“pdf”)
{
AddHeader(“内容类型”、“文本/html”);
WebClient客户端=新的WebClient();
回答。写(“alt:”);
Response.Flush();
Response.Close();
Response.End();
}
其他的
{
AddHeader(“内容类型”、“文本/html”);
WebClient客户端=新的WebClient();
回答。写(“”);
Response.Flush();
Response.Close();
Response.End();
}

我能够解决类似的问题(模态窗口internet explorer中的pdf) 通过取出iframe。相反,将pdf加载到html对象元素中。 请参阅下面的链接:

总而言之: 无法工作的设置:

jqueryfloatbox,用iframe加载html片段,将aspx页面加载到iframe中,将pdf加载到aspx页面中

现在运行的设置:

jqueryfloatbox,加载html片段,追加对象元素。 在附加对象元素之前,请设置数据
object元素的属性设置为aspx页面url

谢谢,但是现在我得到了相同的行为,只是文件是在本机应用程序中下载和打开的。这只在我发布我的网站后第一次起作用。谢谢@AJ,我试过了,但得到了同样的结果。我认为问题更多的是缓存问题(参见上面的编辑)。
if (sDocType == "pdf")
{
    Response.AddHeader("content-type", "text/html");
    WebClient client = new WebClient();
    Response.Write("<html style='margin:0px;padding:0px;'><head></head><body style='margin:0px;padding:0px;'><object height='100%' width='100%' name='plugin' data='" + Request.Url.ToString() + "&embed=true' type='" + zGetContentType(HttpContext.Current.Request.QueryString["docType"]) + "'><param name='src' value='" + Request.Url.ToString() + "&embed=true' />alt : <a href='" + Request.Url.ToString() + "&embed=true'>View</a></object></body></html>");
    Response.Flush();
    Response.Close();
    Response.End();
}
else
{
    Response.AddHeader("content-type", "text/html");
    WebClient client = new WebClient();
    Response.Write("<html style='margin:0px;padding:0px;'><head></head><body style='margin:0px;padding:0px;'><iframe frameborder='0' scrolling='no' height='100%' width='100%' src='" + Request.Url.ToString() + "&embed=true' /></body></html>");
    Response.Flush();
    Response.Close();
    Response.End();
}