Running Web Site As A Root Site

If you're not using IIS but the inbuilt web server of Visual Web Developer (VWD) or Visual Studio (VS) then, by default, you will be running your website under a virtual application path that is the projects directory name.

The problem with this is that you can no longer use absolute paths in standard html controls. With controls we can use the "~" at the begining of a path name to make a fully qualified path.

For example the following 2 controls should produce the same result but only the asp control displays the image.

<img src="/images/happy.jpg" />
<asp:Image ID="Image1" ImageUrl="~/images/happy.jpg" runat="server" />

So how do we get around this? Before microsoft released Service Pack 1 for VWD & VS you would have had to go through setting up an External Tool as described in ScottGu's Blog. Now however, it's made a lot easier. First download and install the relevant service pack from Microsofts website: VWD Service Pack 1, VS Service Pack 1.

Then it's as easy as selecting the website project within the Solution Explorer followed by selecting the Properties Window (F4). Next change the Virtual path to "/" so it runs as root and that's it!