【问题标题】:Pushing out a PDF file to IE from an ASP.NET 3.5 site从 ASP.NET 3.5 站点将 PDF 文件推送到 IE
【发布时间】:2010-10-25 00:43:51
【问题描述】:

我的应用程序将 PDF 文件推送到弹出式(例如,没有菜单/工具栏)浏览器窗口(以响应用户单击按钮)。这适用于除 IE7 之外的所有浏览器。在 IE7 中,我得到的只是一个空白窗口。

这是推出 PDF 的服务器端代码:

private void StreamPDFReport(string ReportPath, HttpContext context)
{
    context.Response.Buffer = false;
    context.Response.Clear();
    context.Response.ClearContent();
    context.Response.ClearHeaders();        

    // Set the appropriate ContentType.
    context.Response.ContentType = "application/pdf";
    context.Response.AddHeader("Content-Disposition", "inline; filename=Report.pdf");
    context.Response.Cache.SetCacheability(HttpCacheability.NoCache);        

    // Write the file directly to the HTTP content output stream.
    context.Response.WriteFile(ReportPath);
    HttpContext.Current.ApplicationInstance.CompleteRequest();
    //context.Response.End();
}

在客户端,当用户按下按钮时,onClick 处理程序中会发生以下情况:

onclick="window.open('RptHandler.ashx?RptType=CaseInfo', 'Report', 'top=10,left=10,width=1000,height=750')

我错过了一些非常基本的东西吗?为什么它可以在所有浏览器中运行,但不能在 IE 中运行?

【问题讨论】:

    标签: asp.net internet-explorer .net-3.5 pdf


    【解决方案1】:

    原来下面的语句导致IE不显示PDF:

    context.Response.Cache.SetCacheability(HttpCacheability.NoCache); 
    

    不知道为什么。

    【讨论】:

      【解决方案2】:

      对于 IE7,我们发现您需要添加一个额外的标题“内容长度”设置为您发送的 PDF 的大小。类似:

      Response.AddHeader("content-length", {pdf的大小});

      【讨论】:

      • 你说的是真的,但不是这样。
      【解决方案3】:

      似乎context.Response.Cache.SetCacheability(HttpCacheability.NoCache); 仅在使用 IIS7 时才有效。

      我将其更改为context.Response.AddHeader("Cache-Control", "no-cache");,它似乎可以与 IE7 和 IE8 一起使用。

      【讨论】:

        猜你喜欢
        • 2012-03-15
        • 2011-10-03
        • 1970-01-01
        • 1970-01-01
        • 2016-07-30
        • 2020-07-19
        • 1970-01-01
        • 2020-07-04
        • 1970-01-01
        相关资源
        最近更新 更多