Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

using ...src="/images/..." gets localhost instead of virtual directory on IIS

Posted on 2007-10-09
12
Medium Priority
?
543 Views
Last Modified: 2013-12-13
i have a virtual directory in IIS called "bob" which is installed in my c:\inetpub\wwwroot\clients\bob folder

when i use <img src="/images/image.jpg"> it points all the way back to localhost instead of the virtual root "bob". i realize that using the forward slash at the beginning of src is doing this, but my intention is to have it look at the root. do i need to configure IIS in some way to have it point to "bob/images" instead of "localhost/images"?
0
Comment
Question by:Jeremy Daley
  • 4
  • 4
  • 2
  • +1
11 Comments
 

Expert Comment

by:kurtfarrar
ID: 20042014
If you're using ASP.NET and it's a server side control you can use the tilda ~ to signify the root of your application.

For example, if your application was in the virtual directory: http://localhost/bob

Then saying <asp:Image ImageUrl="~/images/Logo.gif" alternativeText="" /> would always display the image at http://localhost/bob/images/Logo.gif regardless of whether your page was in http://localhost/bob
or
http://localhost/bob/subdir1/subdir2/subdir3/subdir4

Also, if you then moved your application to a different virtual directory: http://localhost/harry/potter the url for the logo would automatically work with that as the new root... ie. it would look for the logo at http://localhost/harry/potter/images/Logo.gif.

I realise you're using PHP, but this may be some help to move to .NET? :o)

Hope this helps!
0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 20042402
i actually program in both PHP and .NET (C#), but to convert this site would be too tedious of a task. it will work fine once i upload it over to the actual host, but i'd like to test in on localhost first.

i guess this is more of an IIS issue than PHP, by the way it uses relative paths on virtual directories.
0
 

Expert Comment

by:kurtfarrar
ID: 20047099
I think it's more likely to be a restriction of HTML rather than specifically PHP. .NET just works around the issue by allowing you to code something which represents 'root of app', and then at runtime, it figures out what the root is and translates it.

Viewing the HTML output of a page in http://localhost/bob/ which uses ~/images/logo.gif would show the image source as http://localhost/bob/images/logo.gif, not a normal relative path but instead an absolute URL.

It's been a while since I've coded in PHP, but you could create a function which does the same as the .NET tilda does... pop it in an file and include that one your pages that need to use the function. The function would return the root location of the website... I'd hope there's a way either view the request/response objects, or through an already existing PHP function to get the web-root? You may need to do some parsing, but at least if it's done in the function you're not having to recode that over and over.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Author Comment

by:Jeremy Daley
ID: 20049079
IIS on Windows XP Pro natively only allows you to create one site (localhost). If I was able to create a new site instead of just a virtual directory under "localhost", the preceeding forward slash would then take me to its root.

I just hope this doesn't require me to buy Windows Server 2003...
0
 

Expert Comment

by:kurtfarrar
ID: 20049118
For testing/evaluation purposes you could always get an evaluation Virtual Hard Disk from:
http://www.microsoft.com/downloads/details.aspx?familyid=77f24c9d-b4b8-4f73-99e3-c66f80e415b6&displaylang=en

It'd allow you to run Windows 2003 Server to see if it does sort things for you before buying... if you did eventually have to.

Sorry I'm no further help.
0
 
LVL 17

Expert Comment

by:nplib
ID: 20049622
if the virtual dir is Called "Bob" then that is the start of the ref point if you want to reference anything in it.

<img src="bob/images/image.jpg">
0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 20050307
yes, but an included file is used in all pages "header.php"... and that means used in all other underlying directories (bob/states/ohio/somepage.php).

so <img src="bob/images/image.jpg"> would no longer be coming from the root "bob", but instead:
bob/states/ohio/bob/images/

make sense?
0
 
LVL 17

Expert Comment

by:nplib
ID: 20051031
Well this is the first you mentioned an include file,

Can you post all code?
0
 

Expert Comment

by:kurtfarrar
ID: 20055186
You could always add a constant variable to your header.php file with the root... in essence the equivalent of putting the root address in the web.config?
0
 
LVL 4

Accepted Solution

by:
Jeremy Daley earned 0 total points
ID: 20565275
i actually ended up downloading a program called iisadmin that allows you to create multiple sites on windows xp professional (only 1 can be running at a time). the site root then became the correct root as i initially wanted.
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20593830
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question