access from asp.net to content outside IIS virtual directory and show it on WEB

Hi,
I need advice how to resolve below problem as simple as possible.
Web Server Platform: W2k3 IIS 6.0
Application platform - asp.net
Application DB - MS SQL 8.0

Is that possible to show jpg images to client using asp.net which are putted outside WEB content - not in directories defined in IIS?

Example:

IIS Virtual Directory - d:\test - direct link to default aspx page http://servername/default.aspx
Image [.jpg] directory d:\images [not included in IIS content]

I would like to show images from directory d:\images on WEB page run from http://servername/default.aspx

Is that possible and how :)

Thanks in advance
Larsen
LVL 3
_Larsen_Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
sasapopovicConnect With a Mentor Commented:
Here is two more solutions:
 - make an ASPX page that will:
     - accept image name (or some id) through request parameters
     - load image from prdefined folder on filesystem
     - serve image through Response
 - make implementation of IHttpHandler that will be registered to listen for .gif and .jpg (or whatever types you want to support) types of images and will do the same thing as I described above for the ASPX page.

One example of such IHttpHandler would be like this:

    public class CachedImagesHTTPHandler : IHttpHandler
    {
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
 
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                string fullFileName = context.Request.FilePath;
                string imageExtension = FileHelper.GetFileExtension(fullFileName);
                byte[] image = this.GetImage(fullFileName);
 
                context.Response.AppendHeader("Pragma", "no-cache");
                context.Response.AppendHeader("Expires", "Mon, 1 Jan 2000 05:00:00 GMT");
                context.Response.AppendHeader("Last-Modified", DateTime.Now.ToString() + "GMT");
                context.Response.Expires = -1;
                context.Response.ContentType = "image/" + imageExtension;
 
                context.Response.BinaryWrite(image);
                context.Response.Flush();
        }
    }

Open in new window

0
 
sasapopovicCommented:
Hi Larsen,

You can make a virtual folder in IIS under the virtual directory mapped to your web application ("d:\test") that will be mapped to images folder ("d:\images"). Then you wold access images from your default.aspx as: <img src="images/image1.gif"/>

So, in IIS you would have:
Default Web Site
--web app virtual directory - pointing to d:\test
----images virtual directory - pointing to d:\images

I hope I understood your question correctly.

Cheers,
Sasa
0
 
_Larsen_Author Commented:
Hi Sasapopovic,

Such configuration is currently implemented, but I would like to avoid access to image throught direct link. as I mentioned there is only application authentication, so I looking for solution for security purpose[script] which shows images from aspx pages which are put in the directory outside IIS content. All images links are in DB so I looking for a mechnism which allow me to show them by aspx page but will be unable to show them by direct link (because image folder will be outside IIS content)
Or some other mechanism which restrict access to images by direct link without authentication [there is no option to enable Windows authentication - there is only application authentication]

Thanks for your response but this is not what I looking for :)
0
 
boro_bobCommented:
You could set up FTP access to a folder on your server, and then you would be able to set up security on that.
0
 
sasapopovicCommented:
I forgot to write that in case you are using solution with IHttpHandler then you will refer to images in your ASPX pages like you usually do. For example: <img src="image1.gif"/>. In ProcessRequest method you will get the content of the image from file system, database or whatever and you will serve it with the right content type. For your ASPX page it will be the same if image was retrieved from file system or it was server by IHttpHandler implemention (in example above it would be CachedImagesHTTPHandler).

If you would make an ASPX page to serve images then you would use images in your other ASPX pages like this:
<img src="myimageserver.aspx?imageid=123&folder=images3"/>

I hope this will help.
0
All Courses

From novice to tech pro — start learning today.