ASP.NET site, wants to run in subfolder not root!

Soldato
Joined
18 Oct 2002
Posts
5,661
Location
Ledbury
I have some problems... With my ASP.NET 2 site it appears to think the root is up one more level that it really is! This of course means i have a lot of issues with the application working correctly. Does anyone have any ideas on this one? I assume it must be very simple :)

Thanks
 
Is this is an application directory under the main website? If so then that may be the application root, but the website root is still at the top level.

To reference objects in the application root, use ~/ eg.

~/images/test.jpg

Note that this will ONLY work for runat="server" controls.
 
Mr^B said:
Note that this will ONLY work for runat="server" controls.

Yeah i know about that, but i don't want to do that at all. I want to be able to work normally!

I think this must be an IIS issue not a .net one? but i could be wrong :)
 
It's not an IIS issue as such, that's how it's supposed to work - if you want something to operate at the root, you put it in the root, not in a sub-folder/application folder/virtual directory.
 
Now you have me confused!

If the application is in the root, where is the "up one more level" from the root?

Can you give an example of where items are physically located, logically located and what url reference you need to give to get to them?

e.g.

e:\inetpub\wwwroot\images\test.jpg
defaultwebsite\images\test.jpg
\images\test.jpg

:)
 
Webserver:
c:\inetpub\wwwroot\Test\Website
http://computer/Test

Dev machine:
c:\projects\Test\Website

On the dev machine all is fine... on the webserver it just won't work :(

If i change the webserver to:
c:\inetpub\wwwroot\Test
http://computer/Test
It makes no difference at all!


images are in /images.

I can get to them if i do: /Test/images/image.gif
but not: /images/image.gif
 
Last edited:
Matt said:
I can get to them if i do: /Test/images/image.gif
but not: /images/image.gif

That's expected - the forward-slash at the beginning of the url points you to the root of the webserver, which is c:\inetpub\wwwroot.

To access something relative to your current location (i.e: from the root of the site) leave off the starting forward-slash character. However, you'll run into problems if you have pages that are in sub-folders of your site; you'll have to start using paths like "../../images/image.gif".

For ASP.Net apps, I'd use the "~/images/image.gif" style path, because then you always know you're accessing something relative to the root of your site (NOT the root of your webserver) no matter where in your site you happen to be.

Saves a lot of headaches, honestly; it's one of the things I really like about it over PHP, for example.
 
I should be able to use /images/test.gif, that's how it's always worked in the past, and that's how it is at work! / should take me to the root of the website, not the webserver. It all works fine through VS.net with the built in external tools web server...
 
A / reference in a url will ALWAYS go to the root of the webserver (unless you intercept and redirect the request of course).

I have no idea how you managed to achieve this using the built-in web server, all I can think of is that you were using ~/ references instead of /.
 
Mr^B said:
A / reference in a url will ALWAYS go to the root of the webserver (unless you intercept and redirect the request of course).

I have no idea how you managed to achieve this using the built-in web server, all I can think of is that you were using ~/ references instead of /.

Er, aren't relative paths from the website root... This is how it's worked with every site i've ever produced! I'm just confused by what .NET is doing with my site!
 
From what you originally posted:

Webserver:
c:\inetpub\wwwroot\Test\Website
http://computer/Test

The webserver root is http://computer
The website root is http://computer
The application root is http://computer/Test

Using a ~/ reference will take you to the application root, so you can use /images fine. a / reference will take you to the website/webserver root and you'll need to add /Test.

If you are accessing your images using /Test/images then the images must be located in c:\inetpub\wwwroot\Test\images

To access them from the /images, you will need to move them up a level (to wwwroot\images) or create a new Virtual directory at wwwroot\images and point it to wwwroot\Test\images.
 
Matt said:
Er, aren't relative paths from the website root... This is how it's worked with every site i've ever produced! I'm just confused by what .NET is doing with my site!

That's contrary to every site I've ever produced then. As previously mentioned, a preceding '/' will always start at the root of the web server. This is of course handy if your site is at the root of the webserver, but in your case, it's not.
 
Ok, clearly my intelligence has been lacking here :D You are all correct, i'm am wrong! (again!). I'll look into it again tonight if i can, and should be able to sort it i hope.
 
Back
Top Bottom