我有一个 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);
但是图像没有显示,所以我偶然发现了这个 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 ?
任何帮助都会非常感谢。