0

I feel like a nub for asking this, but I can't figure it out.. I've found several posts (here's one) saying that to use a relative path from the root of your site, start the path with /, ex:

<img src="/images/img1.jpg" /> 

My file hier. looks like

-root -images -css -index.aspx -subFolder -test.aspx 

Now when I use the src path as shown above, it doesn't work in either index.aspx or test.aspx, but when I remove the /, it works for index.aspx. In test.aspx, I used ../images/img1.jpg and it works. What gives? Why is my example above not working?

4
  • Is this from Visual Studio, or when it's actually deployed? Commented Oct 31, 2011 at 21:47
  • When project is launched locally via VS Commented Oct 31, 2011 at 21:51
  • So what does the URL look like in the web browser when you run it? I may be thinking of something else, but I remember VS sometimes inserting an extra directory sometimes. Gave me fits. Commented Oct 31, 2011 at 22:00
  • Bah, yeah.. apparently the "root" folder is the folder above my root folder.. Thats dumb. I'm going to have to go and change all my paths when I deploy my site? >_< Commented Oct 31, 2011 at 22:11

2 Answers 2

1

Your site is probably in a virtual directory, so the "/" refers to the actual web root as IIS (or whatever web server) sees it - maybe the folder above your 'root' folder

.

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

3 Comments

Thanks, yeah that was it. Why would it do this? The folder above that is Websites where all my VS2008 projects are. This means I'm going to have to change all my paths when I deploy to the server?! Do you know by any chance if there is a way to configure the 'root' folder in VS?
I don't run sites from VS, so I don't really know. But I don't think so. I use IIS 5 on XP, so there is only one root (or 'default') site. Anything else must be virtual - which sucks because that is not how it works in production with a 'real' web server. I keep a 'rootFolder' string in memory, which I prepend everywhere. The value is '/root' for dev, and just '/' for production. A pain, but it works.
Oh, I gotchya about the virtual directory now.. it doesn't actually go to the parent folder of the 'root'. I was able to change the root by selecting the website in solution explorer and changing Virtual Path to / in the properties panel :) Thanks again!
1

The relative paths work because they are traversing the directory based on the location, so for index.aspx it needs to go into images folder and get the img1.jpg, for test.aspx it needs to go up one level .. then into the images folder and get the img1.jpg.

Absolute paths are based off of were the application is installed from based on IIS settings. If you are just testing this from that folder your absolute path needs to include the root folder. /root/images/img1.jpg and then it will work from both test and index with the same absolute path.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.