Fooling VS to develop in http://localhost

How to trick VS into using http://localhost instead of http://localhost/appname

Whenever you create an ASP.NET project with Visual Studio 2003 it will create the URL on your machine like so.....

http://localhost/appname

The problem with this is that you may want to reference all images/stylesheets etc with an absolute path ...

<img src="/images/me.jpg" alt="Me"/>

Personally, I like to develop using the exact folder structure as I will have when a site goes live, but VS wont allow you to create an ASP.NET project at http://localhost - it always appends the application name.

Here is how I get around this problem

  1. Set your IIS root to your wwwroot folder
  2. Create your project using VS (eg, MyWebSite)
  3. Now set your IIS root to wwwroot\MyWebSite
  4. Create a virtual folder inside MyWebSite called "MyWebSite" and point it to wwwroot\MyWebSite

VS will still use http://localhost/MyWebSite in your browser, but it is infact pointing to http://localhost, so all of your absolute path references will work perfectly!

 

Share this article!

Follow us!

Find more helpful articles: