如何显示存储在本地驱动器上的图像? [英] How to display image which is stored in local drive?

查看:160
本文介绍了如何显示存储在本地驱动器上的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我所要显示存储在我的本地磁盘C中的图像的ASP页:
即..
C:\\ Program Files文件\\肾上腺素\\肾上腺素\\ UPLOADEDFILES \\ TemplateFile \\ abc.jpg的

I have a asp page in which i have to display the image which is stored in my local disk C: i.e.. C:\Program Files\Adrenalin\Adrenalin\UploadedFiles\TemplateFile\abc.jpg

我怎么能做到这一点...我不能够这样做。
作为规定,并且图像不显示代替它显示与图像的名称的空像保持网址为不可用。

how can i do that...i am not able to do so. the image is not displayed instead it shows a empty image holder with the name of the image as specified and URL as not available.

请帮忙....

推荐答案

您将有权限问题如果图像是网站文件夹之外。传统上,网站的网络服务用户帐户,这将限制该文件夹的外部访问的文件下运行。您将需要提取具有类似访问的文件夹中的文件,它的极不明智这么做的,特别是从程序文件。

You will have problems with permissions if the image is outside of the web site folder. Traditionally, web sites run under the NETWORK SERVICE user account, which will limit access to files outside of the folder. You will need to extract the file from a folder with similar access and it is extremely unwise to do so, particularly from Program Files.

您应该通过网页或Web服务,它不公开的图片投放外部网站的事实可能是代理文件。你需要确保目标文件夹C:\\ Program Files文件\\肾上腺素\\肾上腺素\\ UPLOADEDFILES \\ TemplateFile有NETWORK SERVICE读取访问

You should possibly proxy the file via a web page or web service, which doesn't expose the fact that the image is served external to the web site. You'll need to make sure the target folder C:\Program Files\Adrenalin\Adrenalin\UploadedFiles\TemplateFile has NETWORK SERVICE Read-access.

如。创建一个空白的ASP.NET页面:

eg. create a blank ASP.NET page:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ImageServer.aspx.cs" Inherits="ImageServer" %>

与code背后:

with the code behind:

class ImageServer
{
  void Page_Load(object sender, EVentArgs e)
  {
    Response.ContentType="image/jpeg"; // for JPEG file
    string physicalFileName=@"C:\Program Files\Adrenalin\Adrenalin\UploadedFiles\TemplateFile\abc.jpg";
    Response.WriteFile(physicalFileName);
  }
}

和通过进入URL测试在浏览器中

And test in your browser by going to the URL

http://<localhost>/<website>/ImageServer.aspx

您应该得到的图像。

然后,在标签内,使用页面的URL作为你的图像占位符:

Then, within the tag, use the URL of the page as your image placeholder:

<img src="ImageServer.aspx" alt="Image served" />

更新:

看你的最新评论,我建议你发送一个查询参数与一些员工code,并用它来查询数据库并获得在Page_Load()方法中相应的文件名。不要发送的文件名作为查询字符串的一部分。

Looking at your latest comments, I suggest you send a QueryString parameter with some sort of employee code and use that to query the database and get the appropriate filename within the Page_Load() method. Don't send the filename as part of the QueryString.

这篇关于如何显示存储在本地驱动器上的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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