Asp.net 如果pdf是由http处理程序和iframe内部处理的,Firefox不会提供pdf

Asp.net 如果pdf是由http处理程序和iframe内部处理的,Firefox不会提供pdf,asp.net,iis-7,url-rewriting,Asp.net,Iis 7,Url Rewriting,我有一个在IIS7 ASP.NET 3.5上运行的网站 我实现了一个http处理程序,它可以处理pdf文件 如果我在Firefox3.0中请求一个pdf文档(www.mysite.com/mypdf.ashx?id=doc1),我会在浏览器中得到结果 现在我的页面上有一个iframe。src属性设置为www.mysite.com/mypdf.ashx?id=doc1 该文档显示在IE7中,但在Firefox中,我只会得到加扰文本。 这在Firefox中可能吗 我找到了这个帖子 有人用modrew

我有一个在IIS7 ASP.NET 3.5上运行的网站

我实现了一个http处理程序,它可以处理pdf文件

如果我在Firefox3.0中请求一个pdf文档(www.mysite.com/mypdf.ashx?id=doc1),我会在浏览器中得到结果

现在我的页面上有一个iframe。src属性设置为www.mysite.com/mypdf.ashx?id=doc1

该文档显示在IE7中,但在Firefox中,我只会得到加扰文本。 这在Firefox中可能吗

我找到了这个帖子
有人用modrewrite尝试过这个解决方案吗?这篇文章已经有几年的历史了,当时没有IIS7的版本。

我在asp.net mvc中这样做,它在IE6、IE7和Firefox 3.5.3上运行良好

这是我的密码:

Html代码:

<div id="ProductDetailsModal">
    <iframe src="<%= Url.Content("~/GetPdf.axd?id=" + ViewData["ProductId"] + "&type=" +  ViewData["ContentType"]) %>" width="100%" height="98%"></iframe>
</div>

希望这有帮助。

IIS 6也没有修改。这是一个只有Apache的进程。还有一些替代方案,如IIS 7重写器模块或。

是否为响应设置内容类型?IE非常擅长猜测文档是什么;firefox依赖于被告知


您需要将ContentType设置为
“application/pdf”

使用http处理程序提供pdf是一件棘手的事情。加载和读取pdf有很多不同的方法。不同版本的AdobeAcrobatReader表现也不同

有时,它试图变得聪明,看看是否可以使用部分请求(206)。因此,您可以在下载完整个文档之前看到第一页。您可能还希望设置正确的缓存头,因为这样可以节省大量带宽

我一直在使用这个http处理程序成功地为PDF服务,没有任何问题。它为你解决了大部分麻烦

public void ProcessRequest(HttpContext context)
    {
        if (!String.IsNullOrEmpty(context.Request.Params["Id"]) && !String.IsNullOrEmpty(context.Request.Params["Type"]))
        {
            IProductBusiness productBusiness = new ProductBusiness();

            var username = context.Session["Username"] as String;
            var password = context.Session["Password"] as String;
            var id = context.Request.Params["Id"].ToInt();
            var type = context.Request.Params["Type"];

            if (id != 0 && !String.IsNullOrEmpty(type))
            {
                var pc = productBusiness.GetProductContent(username, password, id, type, string.Empty);

                if (!String.IsNullOrEmpty(pc.Name) && !String.IsNullOrEmpty(pc.Extension) && pc.Extension.ToLower() == "pdf")
                {
                    var len = pc.File.Length;
                    byte[] output = Convert.FromBase64String(pc.File);
                    context.Response.Clear();
                    context.Response.ContentType = "application/pdf";
                    context.Response.AddHeader("Content-Disposition", String.Format("FileName=\"{0}\"", pc.Name));
                    context.Response.AddHeader("content-length", output.Length.ToString());
                    context.Response.Cache.SetCacheability(HttpCacheability.Private);
                    context.Response.Expires = -1;
                    context.Response.Buffer = true;
                    context.Response.BinaryWrite(output);
                    context.Response.End();

                }
                else
                {
                    context.Response.Write("Erreur lors du chargement du fichier.");
                }
                context.Response.Clear();
            }
        }
    }