The Mighty Blog

Feb13

Written by:Will
2/13/2008  RssIcon

Sometimes when you are programming or debugging a site, or even when you are using certain 2rd party controls, you cannot effectively do so unless viewing the site using an actual URL. "Localhost" might be causing grief in any number of ways. Here is how to mask or fake a domain name...

First of all, you will need to be running Windows and have your system configured to have and run IIS.  After that, the rest is cake...  The first thing we need to do is determine what URL you want to use.  In our example here, I will choose to use "www.anywhere.com"

Go into IIS, and enter the properties for your site.  Unless you are running a server instance of Windows, you will only have a single site.  Right click on it to get to the site properties.

In the "Web Site" tab, click the "Advanced" button.

Click the "Add" button to add an identity to the site.  Enter the port as number 80, and then enter the URL into the "Host Header Name" field.  (Please note that you might want to repeat this step if you intend on not using the "www." in the URL.)

Click OK to exit out of all of the dialogs and to save your changes.

Go into your system32 directory.  This is either found in the WINDOWS or WINNT directory on your hard drive.  Either way, continue to the following directory.

C:\WINDOWS\system32\drivers\etc\
C:\WINNT\system32\drivers\etc\

Within this directory, there is a file named "hosts".  Make a copy of this file to use as a backup in case you mess something up somehow.

Now, open up the hosts file using NotePad.  Add the following lines of text to the file and save your changes.

127.0.0.1 anywhere.com  # localhost alias
127.0.0.1 www.anywhere.com # localhost alias

That's it!  Your site should already be responding to requests made to the anywhere.com domain.  On small occasions, you may have to restart IIS, or clear your local DNS cache.  Otherwise, your site is ready to use the domain name locally. 

7 comment(s) so far...


Thank you so much.
Worked like a charm

By Evan Cutler on   10/2/2008

My pleasure!

By wills on   10/2/2008

Have you find a workaroud to use with the VS 2008 built-in test server ? It is on port 1884 (normally) and capturing this port in IIs does any good because this test server is not related to the default site visible in IIS

By Philippe Forget on   11/7/2008

Ok the preceding one was a newbie question... You cannot modify such parameters for the built-in VS2008 test server. What you can do is to setup your project to use IIS instead of this test environment. To do so, you must go in your project properties page (Project-> Properties of [project name]). Then select the Web tab. In the server section of this form you can select Use IIS web server.

By Philippe Forget on   11/7/2008

You answered your question before I could. Thanks for the help! ;)

By wills on   11/7/2008
Gravatar

... worked great but what if I want to set up several domains to test .. ech pointing to different folders on my HDD?

By Stef on   8/11/2009
Gravatar

Such a scenario is a good use case to upgrade to use Vista, or Windows 7, where you can do this out of the box with a newer version of IIS. Otherwise, there are 3rd party add-ons for the earlier versions of IIS that allow you to do this (none are free). If you're cheap, like I am, then you can either write a batch file to switch the sites, or do it manually. This usually is not a big deal, as we typically only would be testing one site at a time anyway.

By Will on   8/11/2009

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 
Add to Technorati Favorites
Tweet about my blog
Will Strohl - The Mighty Blog - RSS Feed

Tag Cloud

Sort by:Tag | SizeRSS
camp   community   dnn   dotnetnuke   dotnetnuke®   event   example   free   get   group   integer   jquery   meeting   module   new   odug   orlando   search   session   think  
The opinions expressed here are the personal opinions of Will Strohl and do not necessarily represent the views and opinions of the DotNetNuke Corporation.
© Copyright 2004-2010 by Will Strohl. All rights reserved.Website Skinned By: Ralph Williams  Website Hosted By: Applied Innovations