我们可以将ImageUrl设置为物理路径吗?
我有一个图像控件
,我必须将其ImageUrl
设置为物理路径
,例如C:\image\image1.jpg< /code> 但控制仅采用虚拟路径。如果我们拥有的路径是物理路径,如何显示该图像?
I have a image control
and I have to set it's ImageUrl
to a physical path
like C:\image\image1.jpg
but control takes virtual path only. How to show that image if path we have is physical path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以在 IIS 中创建虚拟文件夹。然后,您可以将图像控件的路径设置为虚拟文件夹的路径。
You could create a Virtual Folder in IIS. You can then set your image control's path to be that of the Virtual Folder.
否,因为客户端(浏览器)无法访问该文件。它需要是一个暴露于“互联网”的文件。您需要将图像移动到其他位置,并使用波形符
~
引用它,这意味着“应用程序路径”:~/Images/images1.jpg
。No because the client (browser) can't access that file. It needs to be a file that is exposed to "the internet". You will need to move the image elsewhere and reference it with the tilde
~
which means "application path":~/Images/images1.jpg
.你不能,图像必须位于 Web 根目录中,最终用户才能看到它,因此它将有一个虚拟路径。
You cannot, the image has to be in the web root for the end user to see it and it therefore will have a virtual path.
您需要一个
代理对象
。当页面需要时,该对象应该从物理路径加载图像作为服务器。它可以像将其加载到静态变量一样简单,也可以是复杂的惰性(按需加载图像)代理,并带有用于跟踪图像更改的文件系统观察器。它可以是一个控件或 Web 服务(也许需要身份验证)。
You need a
Proxy Object
. This object should load the image from physical path as an server it when the page needs it. It can be as simple as loading it to a static variable or a complex Lazy (load image on demand) proxy with file system watcher for tracking changes of images.It could be a control or web-service (maybe authentication is needed).
图像仍然必须放置在本地服务器根文件夹中。不是物理路径。
Still the image has to be placed in local server root folder. Not a physical path.
不。作为软件开发人员,我们不直接与物理层交互。物理层(通常)是旋转盘上的磁性颗粒。没有物理路径可以到达它。我们在物理层之上的几个抽象层上进行操作。
No. We, as software developers, do not directly interact with the physical layer. The physical layer is (usually) magnetic particles on a spinning platter. There is no physical path to it. We operate at several layers of abstraction above the physical layer.