2

I need to display an Image in web page. But the Image doesn't exist in the Web directory. If the image is under web directory I know that just "../Images/TN/my.jpg" will work. But the image is available in "D:\Images\TN\my.jpg" and My web site is deployed in "C:\apps\mywebsite".

How do I convert the "D:\Images\TN\my.jpg" path to a relative path so that the Image will be visible in web page?

3
  • Short answer: You cant. That would be one large gaping security hole. Commented Jan 21, 2011 at 6:47
  • @leppie Ye! But I wasn't able to figure out what would be security hole here? Web application and the Images folder are in same server then why was this not allowed? Commented Jan 21, 2011 at 7:00
  • 1
    Think about what happens if the 'hacker' can go to ../../../foo. Commented Jan 21, 2011 at 7:22

3 Answers 3

3

You cant show images if they are not in a virtual directory. Try holding then in your application folder itself or if its not feasible then make your Folder holding the image as a virtual directory in the IIS and mount it in your application folder.

Here's what you need to do (way i prefer),

  1. Open IIS manager.
  2. In Connections under Sites Select your Website and RightClick on it.
  3. Select `Add Virtual Directory`... from the Context menu.
  4. In The dialogue box that opens Enter the Alias name of your choice like **`"GlobalImages"`**
  5. Browse the physical path of the Folder you want to and Select it and Click OK.

You will have it available for relative url in that website. like

www.example.com/GlobalImages

When you set that in IIS, it is automatically added to your Solution's Project.

Here is the MSDN link if you want..

http://msdn.microsoft.com/en-us/library/ms751432.aspx

Sign up to request clarification or add additional context in comments.

2 Comments

Can you point me to the URL that has step by step process for the second option?
This should be mark as answer. Thanks @Shekhar_Pro :)
0

Easiest thing to do is probably set up a handler and use the generic image name. While local, point to the D:. While on the server, point to the web path. (At least so long as you're not keeping them within the virtual directory that is).

Comments

0

TO fetch this point, we always write the absolute directory for images or other resource.But if the resource in the web server, i use the relative directory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.