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

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

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


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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

_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 :)
You could set up FTP access to a folder on your server, and then you would be able to set up security on that.
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
                return false;
        public void ProcessRequest(HttpContext context)
                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;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.