如何使用asp.net网页从phyical路径显示pdf文件 [英] How to show pdf file from phyical path using asp.net web page

查看:57
本文介绍了如何使用asp.net网页从phyical路径显示pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Freinds,



请帮助显示使用asp.net已存在于我的实际位置的pdf文件



提前谢谢。

Hi Freinds,

Please some one help to show pdf file which already exists in my physical location using asp.net

Thanks in advance.

推荐答案

这不是 MapPath 的工作原理。 />


首先,不仅在主机的文件系统中使用绝对路径将是一个非常糟糕的做法,并使您的网站不可移动和不可维护,但使用该文件从您的示例中获取位置并不总是技术上可行。通常,Web应用程序在沙盒环境中执行,这不会让您直接访问主机的文件系统。您只能引用为您的站点设置的根目录下的文件(root的表示法是'〜','〜/。')。



你应该使用只有相对文件路径(相对于使用的文件的位置)或相对于根目录通过我的 MapPath ,例如:

This is not how MapPath works.

First of all, not only using absolute paths in the host's file system would be a very bad practice and render your site non-movable and non-maintainable, but using the file with the location from your example it is not always technically possible. Normally, Web applications are executed in sandboxed environment which doesn't give you direct access to the host's file system. You can only reference files under the root directory set up for your site (the notation for root is '~', '~/.').

You should use only the relative file paths (relative to the location of the file using then), or relative to the root directory through my MapPath, for example:
string path = Server.MapPath("~/data/Sample.pdf");





文件的位置如D :/Folder1/Sample.pdf可能完全无法访问。



此外,您可以使用从方案开始的完整URL,但随后您的URL应该包含您的网站,协议,端口等,这可能不太便携。请参阅: http://en.wikipedia.org/wiki/URI_scheme [ ^ ]。



例如,如果你的网站域名为www.mySite.com,您的URL可以是http://www.mySite.com/Sample.pdf。基本上,没有必要在同一个域中使用这样的地址,只是不切实际。



-SA



The file with the location like "D:/Folder1/Sample.pdf" could be totally inaccessible.

Also, you can use full URLs starting from the scheme, but then your URL should carry your Web site, protocol, port, and so on, which could be less portable. Please see: http://en.wikipedia.org/wiki/URI_scheme[^].

For example, if your Web site domain is "www.mySite.com", your URL could be "http://www.mySite.com/Sample.pdf". Basically, there is no need to use such addresses in the same domain, just impractical.

—SA

这篇关于如何使用asp.net网页从phyical路径显示pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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