Skip Navigation LinksHome > View Post

Setting up two web sites in IIS7

I've just installed Vista and enjoyed a relatively seamless install experience (had to update the BIOS on my new laptop but can't really blame vista for that).

One of the coolest things about Vista is that we get to see IIS7 and the funky features we were promised all that time ago.

When you first open the IIS admin console you're in for a shock... it feels bizarre.

IIS7's admin console

However, one feature I'm particularly happy to see is the ability to host multiple root web sites. Previously this feature has only been available on Server OS versions.

There's no place like 127.0.0.1

As usual, you have one Default Web Site and you access this at localhost (or your machine name or 127.0.0.1 etc).

Now imagine your company has two websites and it's been impossible for you to run both versions on your development machine because both reference links via the root (e.g. href="/somepage.aspx").

Note: I always recommend that you try to write a website such that it operates in a location transparent way (i.e. that it could be dropped in as a virtual directory at any level and still work fine). It just makes life easier in the long run. However, maybe you inherited a site or maybe you have valid reasons for referencing the root folder - if so, you're going to love this
First thing we need to do is create a fake alias for your machine to be your second domain, how about localhost2?

The easiest way to do this is create an entry in your host file that points to 127.0.0.1 as shown below. You'll find your HOSTS file in the C:\windows\system32\drivers\etc\ folder.

an extra entry in the Hosts file

Now if you type http://localhost2/ into your browser, you should see your default web site.
Note: You'll need to run your text editor as Administrator to edit the hosts file.
Now lets add a second website to IIS:

Add Web Site menu item

Let's call it "localhost2" and point it at a new folder called "C:\inetpub2". We could use a different port but we like port 80 because we don't have to type messy urls. So let's stick with that.

Now here's the trick. If we're using port 80 - how will IIS know to redirect requests to my new site?

This is where the "Host header" setting leaps in. IIS can examine the request to see what url was requested and forward those requests appropriately.

Add Web Site Dialog

Now browse to localhost2 (do a CTRL+refresh to ensure you're not looking at cache) and you should be looking at your inetpub2 folder.

Tags: ASP.NET

 
Josh Post By Josh Twist
9:54 AM
21 Nov 2006

» Next Post: Brighten up your traces with a splash of colour
« Previous Post: SSIS Compress File Task now with added decompression

Comments are closed for this post.

Posted by bill Staples @ 22 Nov 2006 5:52 PM
I couldn't agree more ;) I blogged about the ability to add more than one site, and other nice additions in a recent blog post of my own here: http://blogs.iis.net/bills/archive/2006/10/23/How-I-fell-in-love-with-Vista-this-weekend-_2800_or-why-you_2700_re-gonna-love-IIS7_2F00_Vista-for-Web-development_2900_.aspx

Posted by Som @ 03 Jan 2007 8:57 AM
That feature is in Apache from day one. Isn't it?

Posted by Josh @ 03 Jan 2007 9:29 AM
It's been in IIS a long time too - but only in the server versions until Vista.

Posted by Sue @ 29 May 2009 8:37 PM
I was wondering if anyone could tell me the steps you need to take after installing IIS 7.0 on Vista that will enable your classic .asp pages to be viewed. I'll definitely be setting up multiple websites, but I can't seem to get things going. I've installed everything and have modified my HOSTS file and have set my page for the site to be Index.asp, but I'm getting this error: "HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid." I've always used IIS 5.0 and have worked with IIS 6.0 and have never had this problem, it's always been easy to set up. Thanks for the help!

Posted by Adryn @ 12 Aug 2009 2:45 AM
Adding additional websites to IIS7 is easy, but how do you connect to the additional websites from another computer. E.g. if my computer with IIS7 has IP 1.2.3.4, from another computer on the network I can just type in http://1.2.3.4 and get to the default website on my computer with IIS7. But how can I connect to other websites that I added into IIS7?

Posted by wally @ 12 Aug 2009 3:02 AM
Hi, really very interesting post!
I would ask somebody for a little question: I've on a Vista PC two web server IIS 7.0 and the emule webserver. This last one works on port 4711 and I want to leave it as it is.
I want to have a virtual folder or a virtual application to my IIS default site (i.e. http://localhost/emule) that redirect it to my emule web server throught the port 80.
If I redirect my virtual folder "./emule" to http://localhost:4711 it works fine but throught the 4711 port.
I need to access it from an external workstation throught the internet that has ONLY port 80 open. But I cannot set the port 80 for emule server because my IIS has to expose other web applications.
How can do It?

Thanks in advance.
Wally

Posted by Andrew @ 12 Aug 2009 2:02 PM
Hello

Interesting post. I'm trying to set up multiple websites offline. Back in 2001 I learnt HTML/ASP/PWS and IIS (5 I think). Seeting up mulitple sites was simple.

After an 8 year gap it seems now that we have Vista and IIS7. Things seem to be a lots more complex:
- I need to know about ports
- I need to edit an external text file
- I need to adopt a "trick" to do something quite straightforward

I'm clearly not criticising the author (thanks for you help!) but am I missing something?


A

Posted by Andrew @ 12 Aug 2009 3:57 PM
OK, boy I was rusty but have learned something. Hopefully things get easier from here on in!

1) High level idea of solution:
a) The overall default page is at C:\inetpub\wwwroot\iisstart.htm

b) Make/store your multiple sites at:
C:\inetpub\wwwroot\folder1
C:\inetpub\wwwroot\folder2
etc, making your own names of course!

c) Create a new page C:\inetpub\wwwroot\index.htm
(or edit C:\inetpub\wwwroot\iisstart.htm)
** Note that you may not be able to edit and save to this folder directly. Save to another folder, then copy across - a nuisance **

d) In the above index.htm write HTML to point to the various start pages, for example:

<html>
<head>
<title></title>
</head>
<body>
<a href="folder1/index.htm">folder1/index.htm</a><br />
<a href="folder2/index.htm">folder2/index.htm</a><br />
</body>
</html>


2) Classic ASP error messages to the browser are turned off by default
a) They can only be turned on globally not on a site-by-site basis
b) This is not a huge problem when developing offline (see reference below for what to do) but online errors are now problematic; system administrators will not easily be persuaded to globally report errors in the browers since this is a security risk (but was allowed before IIS7?)
Solution:
- Offline solution see below
Online...
- move to a dedicated server
- move to a ASP.NET or
- move to Linux + the LAMP environment

3) Numerous other unhelpful defaults
a) Under ASP icon in IIS7:
- set EnableParentPath to True (although consider security online/offline)

Under Debugging Proporties
- set Enable Client Side Debugging to True
- set Enable Server Side Debugging to True
- set Send Error Messages to Browser to True
Now for the really hard stuff:
P Durrant at http://forum.manifold.net/forum/x54784 says:

#28-Apr-08 06:24

after much random clicking i found that in the IIS settings under ASP --> services --> COM+ properties

Execute In MTA was set to false, i set this to true and everything lept into life

hope this helps

(Well done that man!)

Posted by Claire @ 06 Oct 2009 2:52 AM
Thanks very much this has been mysterious to me for a long time, now delving into umbraco it becomes a necessity to run more than 1 website in the root. This post helps a lot & saves typing cryptic port numbers.

Posted by andiwivs @ 26 May 2010 6:09 AM
Thanks Adryn, exactly what I've been trying to achieve for a long time. And it gives me the best of both worlds, ie simple local paths and accessible external ones. Cool.

Posted by Andrew @ 10 Sep 2010 6:57 PM
Thanks Josh, great post! This really cleared up a lot of things I had trouble understanding about IIS7....

Posted by erin leager @ 21 Jan 2011 6:44 AM
where is this host at 1.2.3.4 as i cannot seem to find it? dead end, you know-e

Posted by ale_duvia @ 19 May 2011 1:25 PM
my localhost2 keeps pointing to the default website, even if i've placed a totally new defaul.html in the new directory!

why!?

Posted by priyanka @ 14 Dec 2011 5:44 AM
You can assign ports and use same domain for multiple websites.

Posted by Raymond @ 22 Dec 2011 7:16 AM
But how do we make the site visible from other hosts?

© 2005 - 2014 Josh Twist - All Rights Reserved.