Ajay
Ajay

Reputation: 554

Set Image Path from outside drive from our application's root directory

I am using ASP image control for image display or HTML image control for that, I want to set the image URL of image that is outside of our web application's root directory... On Which way this is Possible???

Upvotes: 0

Views: 997

Answers (1)

TheCodeKing
TheCodeKing

Reputation: 19220

You can use Response.WriteFile to serve the image file from a custom handler.

Response.ContentType = "image/jpg";
Response.WriteFile(@"c:\images\myimage.jpg")
Response.End();

Alternatively you can also achieve this using a custom VirtualPathProvider. This allows you you remap specific paths to alternative streams, whether it's the database or another location.

If your application is a child application in IIS, and you actually just want to reference a parent image, just use a slash to get back to the root, /myimage.jpg, or an absolute path to reference a different application http://www.myotherapp.com/myimage.jpg.

Upvotes: 2

Related Questions