News

Copyright © 2008-2019 Paula DiTallo

Tag Cloud



How do I Configure Multiple Web Sites in IIS or How do I Add/Edit Host Headers?

You may need to map multiple web sites with the same port number or you may want to map an IP address that has been set to a netscaler vip/ip to multiple servers. IIS 6.0+ allows you to do that with a feature called Host Header Names. For the official details, review Microsoft's web site:   http://support.microsoft.com/kb/324287

Here's how it works:

Let's say you have a DNS entry called  MetroDesignDev.LoadBalanced.Twins.com @ ip address: 10.201.25.216  and one of the load balanced twins (ServerAlphaTwin) has an address of 10.201.25.111 and the other (ServerBetaTwin) has an address of 10.201.25.112.

To set this up on the ServerAlphaTwin you would do the following:

1. Click Start> Administrative Tools, and then click Internet Information Services (IIS).
2. Where you see the name of the server (in this case ServerAlphaTwin), expand Web Sites.
3. Right-click the Web site that you need to change (usually Default Web Site), click on Properties.

The Properties dialog box will appear--once it does do the following:
4. Click on the Web Site tab, click Advanced.
5. Under Multiple identities, click the IP address, and then click Edit.

When the Advanced Web Site Identification dialog box is up:

6. Under the Host Header Name, type the host header that you want. In this case, type MetroDesignDev.LoadBalanced.Twins.com
7. Add the port number (usually 80)
8. Select the IP address in the list if there, if not type it in. In this case it would be (10.201.25.216)  and then click OK.

What you will see in this dialog box for ServerAlphaTwin is:

IP Address               TCP port          Host Header Value
10.201.25.111         80                    <default>
10.201.25.216         80                     MetroDesignDev.LoadBalanced.Twins.com

For ServerBetaTwin repeat steps 1-9, replacing the ip addresses accordingly.

What you will see in the Advanced Web Site Identification dialog box  for ServerBetaTwin is:

IP Address               TCP port          Host Header Value
10.201.25.112         80                     <default>
10.201.25.216         80                     MetroDesignDev.LoadBalanced.Twins.com

 So now both the Alpha and Beta servers can be accessed by addressing the MetroDesignDev.LoadBalanced.Twins !

Wednesday, November 5, 2008 2:40 PM

Feedback

# re: How do I Configure Multiple Web Sites in IIS or How do I Add/Edit Host Headers?

Hi,

In our application I have to create a domain at godaddy.com for each registered users. I have created the domain(thiagu.info) for each user at godaddy with the A record of my staged server IP. If I click the domain name my user profile should be open. In our staged server I need to add a host header value and port number programatically in IIS using asp.net with c#. please help me regarding this.


Regards,
Subburaj.S 3/16/2009 1:17 AM | Subburaj

# re: How do I Configure Multiple Web Sites in IIS or How do I Add/Edit Host Headers?

Subburaj. S--

Here is some starter code for you on inserting new host headers with c#/system.directoryservices reference.

Another helpful reference is from Walt Oliver's blog:
http://learn.iis.net/page.aspx/285/sample-hosting-provisioning-scenario/

------------------- starter code -----------------------------------------------------

// general example to add host headers -- if you need to add more than 1, wrap this logic in a
// foreach or while loop.
using System.DirectoryServices;
using System;

public class IISHostHeaderTest
{

public static void InsertHostHeader(string hostHeader, string yourSiteID)
{

DirectoryEntry yourSite = new DirectoryEntry("IIS://localhost/w3svc/" + yourSiteID );
try
{
//yank whatever is in the serverbindings property.
PropertyValueCollection serverBindings = yourSite.Properties["ServerBindings"];
serverBindings.Add(hostHeader);

//copy the content to new array
Object [] freshBindingList = new Object[serverBindings.Count];
serverBindings.CopyTo(freshBindingList, 0);

//Write to iis metabase
yourSite.Properties["ServerBindings"].Value = freshBindingList;
yourSite.CommitChanges();

}
catch (Exception e)
{
Console.WriteLine(e);
}

}
}

//----------- to call this code chunck do the following:
//test driver
public class TestIISHostWriteApp
{
public static void Main(string[] args)
{
IISHostHeaderTest.InsertHostHeader(":80:yourtest.com", "1");
}
} 3/16/2009 3:14 AM | paula ditallo

Post A Comment
Title:
Name:
Email:
Comment:
Verification: