I have a Default Web Site and another web application (let's call it Application2) inside the Default Web Site in IIS7.

I have 2 registered domain names, let's say www.example.com and www.example.net.

I would like to configure things that when I open www.example.com I get Default Web Site, when I open www.example.net I get Default Web Site/Application2.

www.example.com -> Default Web Site
www.example.net -> Default Web Site/Application2

How can I do that?

Accepted Answer

First you need to decide if your going to use Name Based or IP Based hosting.

IP-Based uses unique ip's to determine which virtual host it will serve and Name Based will actually use the host header which is sent by your client browser.

So let's see two scenarios:

Scenario # 1 (ONE IP TO SHARE)

You have a server with only one IP, could be either private or public as long as the domains you are serving are properly configured in the dns serving you internally or your client externally (NAT).

I suggest that for the sake of this tutorial you stop the default website. Ok.

You will set up one site in II7 and name it accordingly. Go to the right hand side of the manager and look for "Bindings" under actions menu; making sure you have the new site selected on your left pane. Now under "Site Bindings" select the ip address you will be sharing between the sites (name based hosting). Under "Hostname" enter domain # 1 "www.example.com", hit ok.

Follow the same procedure above with the other domain or domains, making sure they have diferent hostnames and same ip's.

That's it. You will now be able to start those sites and run them at the same time.

The same principle above applies if your using the "Default Site". "Default Site" is just a name MS gave the default created one.

Scenario # 2 (MULTIPLE IP TO SHARE)

If you have either some private or public ip to spare, or at least until you do the exercise the only diference here is that sites you will set up and don't have to specify the "Hostname" per each site, as this is basically done in the DNS zones itself. The sites will respond for any request made to those ip's on port 80 regardless.

When will you need to use multiple Ip's to serve websites. Well it all depends.

Some reasons are: Network Isolation (Security), Applications which don't work well under name based hosting, SSL Certificates Bindings 443(PRE II7), and mostly complete control over site. There are of course more reasons, but I'll let others write a bit also.

Have fun.

Written by Codex73
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki