【发布时间】:2013-10-09 13:01:58
【问题描述】:
我有一个 asp 页面,我必须在其中显示存储在本地磁盘 C 中的图像:在某些情况下来自网络驱动器 示例路径:--C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg 我在后面的c#代码中完成了以下代码
Image image = new Image();
image.Height = 150;
image.Width = 150;
string path = @"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg";//this path will come from database dynamically this is for test only
image.ImageUrl = path;
this.Controls.Add(image);
但图像没有显示,所以我偶然发现了this SO Question,我更新了我的代码,如下所示
对于显示图像的页面
Image image = new Image();
image.Height = 150;
image.Width = 150;
string path = @"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg";
image.ImageUrl = "ImageWriter.aspx?path=" + path;
this.Controls.Add(image);
对于代理页面
Response.ContentType = "image/jpeg"; // for JPEG file
string physicalFileName = Request.QueryString["path"];
Response.WriteFile(physicalFileName);
这很好,但我有两个问题
1) Why the file is accessible from the physical path while proxy from page but other page cannot able to access it ?
2) And is there any other way to do it ?
任何帮助将非常感谢。
【问题讨论】:
-
您可能希望限制
ImageWriter.aspx可以处理的文件范围:您现在可以访问网络服务器上“IIS 用户”可以读取的任何文件。 -
是的,但我可以像@David 所说的那样强制用户进行身份验证
标签: c# asp.net image web-applications