如何在应用程序路径以外的路径中显示iframe内的PDF? [英] How to display a PDF inside iframe from path other than application path?

查看:98
本文介绍了如何在应用程序路径以外的路径中显示iframe内的PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想在Iframe中显示驻留在服务器光盘上的PDF格式。



我使用下面的代码:



< iframe id =if1src ='file:E:\Shared-Files \DisplayPDF.pdf'width =700pxheight =150px>< / iframe>



但我无法查看此PDF格式。

任何人都可以建议在iframe中显示PDF的正确方法吗?



(稍后在.cs页面中我会根据文件名设置src属性以便制作它动态:

if1.Attributes.Add(" src",pdfPath);)



我尝试使用< object>但是我不想用它。



提前谢谢,

Janie D

Hi,

I want to display a PDF residing on disc of server from Iframe.

I am using below code:

<iframe id="if1" src='file:E:\Shared-Files\DisplayPDF.pdf' width="700px" height="150px"></iframe>

But I am not able to view this PDF.
Can anyone suggest what is correct way to display PDF inside Iframe?

(later on in .cs page I will set src attribute as per file name so as to make it dynamic:
if1.Attributes.Add("src", pdfPath);)

I tried using <object> but I do not want to use it.

Thanks in advance,
Janie D

推荐答案

错误的问题。 Web应用程序中的路径与应用程序路径无关。相对URI寻址基于当前页面的位置。换句话说,如果您的主机页面有一些位置,并且您使用iframe内容的URI作为frames / myFrame.html(与./frames/myFrame.html相同),则表示资源已被占用来自主页位置目录的子目录frames。



但是像file:E:\Shared-Files \ .. 你试图在Web应用程序中使用它们是非法的。 HTTP服务器执行您的应用程序是一个沙盒环境,它允许您只访问站点根目录下的文件系统对象。因此,绝对目录只能基于此根目录计算。在ASP.NET中,它可以基于 MapPath 完成: http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx [ ^ ]。



对于URL,应该使用http://或https://URI模式基于站点的根构建,或者更常见的是,应该是相对的。



-SA
Wrong question. Paths in a Web application are irrelevant to the application path. Relative URI addressing is based on the location of a current page. In other words, if your host page has some location, and you use the URI of the iframe content something as "frames/myFrame.html" (same as "./frames/myFrame.html"), it means the resource is taken from the sub-directory "frames" of the directory of your host page location.

But URIs like "file:E:\Shared-Files\..." you are trying to use are simply illegal in Web application. The HTTP server executes your application is a sandboxed environment, which allows you to access only the file system object under the site's root directory. So, the absolute directory can be only calculated based on this root directory. In ASP.NET, it can be done based on MapPath: http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx[^].

As to URLs, the should either be built based on the site's root using the "http://" or "https://" URI schema, or, more often, should be relative.

—SA


这篇关于如何在应用程序路径以外的路径中显示iframe内的PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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