How to create your web site, application, and URLs in IIS

22 September 2015

My team had just finished a .NET web service and AngularJS web app that used it and we wanted to deploy to IIS.

Adding applications to the default site

When newly installed, IIS has one default website that listens for calls on the standard HTTP port, 80. According to Microsoft, each website you create needs at least one application. So one option is to add your service and app to the default site. However, each app you add must have an alias. This alias is appended the URL of the default site.

However, each app you add must have an alias. This alias is appended the URL of the default site. For instance, below I've added two apps to the default site, with aliases a and b. default iis

You can browse to the b app by browsing to http://localhost/b.

Problems with this approach

But what if your client doesn't want to type /b to view the website?  For instance, they might have configured www.b.com on their intranet to point to server 192.168.0.1.

But in the setup above they would have to browse to www.b.com/b. Very annoying.

Secondly, it's better to have each app in it's own site to allow greater control, being able to restart each site individually, and avoiding web.config clashes.

(To redirect a URL to a specific server, alter your hosts file, like this: hosts

Put each app in its own site

So rather delete the default web site and create a site for a and a site for b, both on port 80, with apps for each inside each site, like this: separate iis sites

In this example, if you browse to http://localhost/a you'll hit web app a, and if you browse to http://www.b.com you'll hit web app b. browsing sites

The important trick here is when creating web site b you need to set the host name, otherwise IIS will tell you it can't handle two sites both trying to listen on port 80. This setting is checked by IIS when receiving a web request and is part of the HTTP request header. host header

Another way of configuring URLs

If the technique above doesn't satisfy what you need to do in your configuration, maybe rewriting can help you.