Tuesday, August 14, 2012

Hosting Multiple Web Sites on the Same Server

So, today I will try to give you a hint about how to host two or more .NET applications on the same IIS. In order to do that, you need to configure a unique ID for each of the application. There are 3 different approaches:


  • Port-Based Routing
  • IP-Based Routing
  • Host-Header Routing
The one that I use and will explain today is the third one: Host-Header Routing. With Host-Header Routing, you can use the same IP address for multiple websites and distinguish each one of them from another by using unique host-header names. Here are the instructions for IIS 7.0 on Windows 7:
  • Go to your Control Panel -> Administrative Tools -> Internet Information Services (IIS) Manager (You can type "inetmgr" on Start -> Run and hit Enter button)
  • At left pane, Right click on "Sites" and click "Add Web Site..."
  • On the window opened, enter the site name, select the physical path to your website files
  • Click on "Connect as..." and enter the credentials which will be used to connect to your website
  • Click "Test Settings..." to make sure your credentials are working
  • Under "Binding" section, enter a unique host name (let's say: "test1"
  • Click "OK" button
You just created your website. It should appear on the list. Now, you need to configure some settings for your website.
  • Right click on the website you just created and click "Edit Permissions..."
  • On "Security" tab, click "Edit" button to add a new user
  • On opened window, click "New" button
  • Click on "Locations" button, and select the top most item (which is your own computer) and click "OK" button
  • In the richtextbox area, type "IIS_USRS" and click "Check Names" button
  • Click "OK" button
  • Set the permissions for IIS_USRS user to full control
  • Click "OK" button
Now, you need to tell your local DNS to find the host-header for your website.
  • Go to "C:\Windows\System32\drivers\etc" folder and find "hosts" file
  • Open "hosts" file with Notepad
  • At the bottom of the file, add a new line and type "127.0.0.1", then hit "Tab" button (to skip spaces) and type your host-header name (in this scenario it is "test1"
  • Save file and exit
It is now time to test your website.
  • Open a web browser and navigate to "http://test1/"
  • If you have a default document, like "Default.html", "Index.html" or "Index.htm", it will appear on the browser. If not, you can add a default document or configure your own default document from website settings
I hope it helps you guys when working on IIS and multiple websites on the same IP...