Chrome浏览器无法从asp.net页面中显示PDF [英] Chrome not displaying PDF from asp.net page

查看:159
本文介绍了Chrome浏览器无法从asp.net页面中显示PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.aspx页面中有一个.pdf文件,像这样:<嵌入SRC =HTTP://.../ShowPdf.aspx ID = 1类型=应用程序/ PDF> 。 Chrome浏览器只显示加载的形象,并挂而不显示PDF(铬PDF浏览器和Adobe插件两个不工作)。其他浏览器打开PDF文件。任何想法?

An .aspx page has a .pdf file in it, like this: <embed src="http://.../ShowPdf.aspx?id=1" type="application/pdf">. Chrome just shows a "Loading" image and hangs without displaying the pdf (chrome pdf viewer and adobe plugin both don't work). Other browsers open the pdf. Any ideas?

推荐答案

我有这个问题也和我多次调研后,终于解决了这个问题。

I had this problem too and I finally solved it after several researches.

我发现的是, HTTP 响应头应具有以下实体头:

What I found is that the HTTP response header should have the following entity-header:

内容长度:文件大小

如果没有指定这个头,Web服务器就会把默认的:

Without specify this header, the web server will put the default:

内容长度:分块

我不知道为什么谷歌浏览器有这个问题,因为正如你所说,在其他浏览器如IE或Firefox,他们提供/打开正确的PDF文件。

I don't know why Google Chrome has this issue, because as you said, in other browsers like IE or Firefox, they render/open correctly the PDF file.

以下是我的code,我来解决这个问题。它的工作在我的情况,现在谷歌浏览器显示我的Web应用程序的PDF文件!

Following is my code that I used to solve this problem. It worked in my case and now Google Chrome is displaying the PDF file of my web application!

    System.IO.FileInfo fileInfo;
    fileInfo = My.Computer.FileSystem.GetFileInfo(fullPathToFile);
    Response.AddHeader("Content-Length", fileInfo.Length.ToString());

我希望我帮助你。

I hope that I had helped you.

下面是一些参考资料,我发现有用:
与Chrome和 PDF处理程序问题;火狐
<一href="http://stackoverflow.com/questions/2773396/whats-the-content-length-field-in-http-header">What's在HTTP头中的内容长度字段?

Here are some references that I found useful:
PDF Handler Problem with Chrome & Firefox
What's the "Content-Length" field in HTTP header?

这篇关于Chrome浏览器无法从asp.net页面中显示PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆