Re: VS.NET, Default Web Site, and relative paths...

Efran Cobisi <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.web
Organization QBGROUP SpA
Message-ID <[email protected]>
Hi Ben,

It depends on where you referenced those pages, images, etc. The
majority of ASP.Net server controls supports the tilde (~) notation for
url references, expanding it to the root of the app they are
instantiated into; so, if your references are inside server controls you
should be (almost) fine.

For example:

<asp:Image runat="server" ImageUrl="~/Images/MyImage.jpg" />
and
<img runat="server" src="~/Images/MyImage.jpg" />
will both point to the MyImage.jpg file, inside the Images subfolder,
related to the root of your web app, no matter if it lives in a virtual
directory (so both your development and production environment will be ok).

Css style sheets are a different beast; they let you use urls (for
background images, for example) relative to where the css reside. So, if
your css is in the ~/Styles subfolder and you want to reference the
aforementioned MyImage.jpg file you should use:

background-image: url("../Images/MyImage.jpg");

HTH,

Efran Cobisi
http://www.cobisi.com

Ben Joyce wrote:
> Morning all.
>
> I am developing a website in VS.NET 2005 on an XP machine and by
> default it has created the site under the Default Web Site on the
> local machine.  When I run my app within VS.NET or browse it mnually I
> find it at the following address:
>
> http://localhost/myapp/default.aspx
>
> Within my application I reference other pages using the syntax
> "/myapp/blah/blah/blah" - (such as the main menu at the root, the
> images folder, and various other shared resources).
>
> This works fine locally and in the development stages, but when in
> production the website will not live under a /myapp folder from the
> Default Web Site root - it will be a new website.
>
> This causes a problem with referencing the site root as "/myapp".
>
> I'd like to find a solution that works in both situations without
> making any code changes when I put the site into production.
>
> Any help or thoughts appreciated.
>
> Cheers,
>
> Ben
>
> ===================================
> This list is hosted by DevelopMentor®  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.