IIS and relative paths - starting points?

sdlangers

Centurion
Joined
Dec 3, 2002
Messages
118
Hi,

this is longwinded, but straightforward... please take a look...

I'm trying to set up a website that will eventually be on its own url, but for now it is in development on my test machine.

i want to include a file like this:

<!-- #Include Virtual="/includes/header.inc"-->

so when i'm finished, my real website would have this url to the include file:

http://www.mywebsite.com/includes/header.inc

but here's the problem - right now its in a local virtual directory at:

d:\inetpub\wwwroot\mywebsite\includes\header.inc

and the virtual directory is set up in IIS to point to mywebsite, so i can view it at:

http://localhost/mywebsite/index.aspx

however, it cant find the include file - it gives the error message as:

Parser Error Message: Could not find a part of the path "d:\inetpub\wwwroot\includes\Header.inc".

so it is skipping the virtual directory's folder.

how do you make it start in the virtual directory so that the link will work the same as it does if you had it on a live site????

thanks for your help
 
sorry - thats a bad example that i gave you.

i need it to work from any directory or sub-directory

if i removed the first / then it would work only for the root directory, so, yes the index.aspx page above would work

but i want to use that same include statement in my sub-directories and the idea of the first / is to make it start from the root of the site.

it works fine as a regular website on the live version... i.e. when i dont have it as a virtual directory... but it wont work as a virtual directory off my localhost site

for example:

it works for http://www.mywebsite.com/subfolder/somepage.aspx

but it doesnt work for the same page on my dev machine at:

http://localhost/mywebsite/subfolder/somepage.aspx

and its the exact same code on both - so i guess its something that i have to change with the virtual directory in IIS

any ideas?
 
If you're happy with how it's working on the "live" site then you probably should alter how your development environment is behaving so that it mimics your live environment.

Change the physical location of your IIS root mapping to be your project's physical root folder. Right now your dev IIS virtual root is (most likely) mapped to:

c:\inetpub\wwwroot

Change it to:

c:\inetpub\wwwroot\yourproject

...if your physical files are actually off of wwwroot, otherwise change it to whatever path contains your project files (IIS doesn't care what its root is mapped to - I change my root mapping so much for different code bases that I created a task bar tool to do it so I don't have to use the clunky management console).

One you've changed the IIS virtual root to point directly to your project you can get to your project as "http://localhost" and all your root relative URLs will work properly.

Paul

PS - One extra word - if you haven't messed with changing your root when doing ASP.Net _and_ if you use ASP.Net validators then you'll want to make a virtual mapping for the aspnet_client folder that physically exists under c:\inetpub\wwwroot. Once you've made this mapping once it'll persist whenever you change the root around. ASP.Net's validator javascript is in that folder so validators won't work if it's not available.
 
Last edited:
thanks paul

i had thought of doing that briefly, but 2 things came to mind

1. security concerns, since i'd have to enable scripts on my main wwwroot directory (maybe this is nothing to be concerned about, but i noticed they were disabled by default)

2. what if you were a developer that had a few websites under development on a dev server - surely there is a way of having them all up and running at the same time without having to switch between them?

in any case, what you said works good - so thank you.. this reply is just for discussion if anyone is interested

thanks
 
Another option might be to create a virtual mapping to only your "includes" folder off the root - that way any project you create could link to it with "/includes/..." regardless of where it was in the virtual heirarchy.

sdlangers said:
2. what if you were a developer that had a few websites under development on a dev server - surely there is a way of having them all up and running at the same time without having to switch between them?

A server can host multiple sites, for sure, but that doesn't mean that you as a developer will run a development environment that works the same way (and hopefully you develop seperate from your live sites!) It might depend on what operating system you have, what web server you have, and what your network will let you get away with.
 
Back
Top