Do you ever get sick of trying to remember the IP address to the local development version of
a site you're working on? Here's a little trick that might help.
In an ideal world, a developer would be able to work on one site at a time and then once finished,
move on to the next project. I'm not sure about you, but that's never really been the case for me.
I've usually got half a dozen projects going at a time which means I've usually got six or so IIS
Web sites set up on my development server. A few years ago, I finally got sick of keeping track
of IP addresses and trying to remember which site was configured where. That's when I started
giving each site a name. For example, I access my local copy of ASP 101 via
http://local.asp101.com/. Don't bother trying to get there... the address won't
work for you, but it's simple, easy to remember, and just as easy to set up.
The secret is what is called a hosts file. It works like DNS in that it maps names to IP addresses,
but unlike DNS it only affects your local machine so you can feel free to name things
whatever you want. You can read more about hosts files from
Wikipedia, but
all you really need to know is that the file is named hosts with no file extension,
it's just a plain text file, and it's normally located here: C:\Windows\system32\drivers\etc\.
The format is straight-forward. Each entry gets its own line that starts with the IP address and
is followed by one or more spaces and the name by which you want to access that IP address.
The line for local.asp101.com in my hosts file looks like this:
192.168.0.200 local.asp101.com
That's it. Simply add the appropriate line, save the file, and you're good to go. Windows
picks up the changes automatically.
Once you start naming your sites you can then take things to the next level and pretty much stop
worrying about IP addresses at all. If you simply put all your development sites on the same
IP address and configure the site's host header value in IIS to match the name you just set up in your
hosts file, you can host all you development sites on one IP address and still access them all
simultaneously.
If you have a tip you would like to submit, please send it to:
webmaster@asp101.com.