Yesterday I checked my RSS feed and found that Scott Guthrie announced that he is starting a new series of posts. That was a great news to hear. Scott is one of the most popular Microsoft managers. He is one of those who played a core role developing Microsoft web platform even the whole .NET framework. He leads core .NET libraries,WPF, ASP.NET, ASP.NET MCV, Sliverlight and IIS teams.
IIS is the lonely web server –rather than web development server - in the Microsoft stack and the most recent one IIS7 add more flexibility, control and ease of use to IIS. There is a bunch of concepts need to be clear in mind when it comes to host information and pages on IIS to allow sharing then over the Internet, an intranet or an extranet. To host data you on IIS you will use websites, application and virtual directories. Those concepts was hanging around from previous versions.
Sites, virtual directories, and applications
Those three concepts is the building blocks you will use to host you websites, web applications, web pages and any other resources. In this post we will discuss the concept of website.
So what is Website?
A website (or web site) is a collection of related web pages, images, videos or other digital assets that are addressed with a common domain name or IP address in an Internet Protocol-based network. A web site is hosted on at least one web server, accessible via the Internet or a private local area network. – wiki-
In IIS a A site is the top-level logical container that specifies how HTTP requests are received and processed - it defines a group of bindings that determine how the site listens for incoming requests, and contains the definitions of applications/virtual directories that partition the site's URL namespace for the purposes of structuring your application content. :) Thanks mike
Ok this is what website means … oops! then it must map to physical folder, physical files, and resources ...etc? yes that’s right.
Web servers works on a client server technology. In the simplest case this means that the client – usually web browser- requests a certain resources webpage, images ..etc from the web server e.g. IIS using an http request. The web server picks up the request and maps it the appropriate website. In IIS there is a default website called Default Website which maps to C:\inetpub\wwwroot folder –inetpub is the default installation folder of IIS- We can add as many as websites we need but the main issue we need to address is that those websites should to be uniquely identified within the IIS server. Otherwise the web server -IIS- will no be able to redirect the incoming http requests to the correct website.
To uniquely identify website you will use site binding to configure Http.sys to listen on IP addresses and ports. Site binding includes two main attributes which is the binding protocol and the binding information. Okay so lets have a look to the DeafultWebsite site binding. Choose the default website> Edit Binding from DefaultSite context menu. As we can see: the binding protocol is http this means that the communication between the client and the server will occur over the http protocol. And we can see the binding information which consists of: IP address, Port and host header.
What this means? this means that when a client requests your web server lets say that we have an intranet server called alpha by typing http://alpha in his browser the web server will pick up the request and maps its to the DefaultWebsite over the http protocol using any available IP address on port 80 which is the default port for http protocol.
Ok,what if we need to have multiple website rather than the DefaultWebsite?
As we stated above IIS is designed to host multiple websites by default each of them must be uniquely identified so to carry out we need to play with binding information parts:
- IP address
- TCP Port
- Host Header
The decision to which way you need to follow is determined in respect of your needs and available resources. Ok lets create additional three website to be host on our machine each to clarify this issue.
Using IP address
In IIS you can configure websites to listen to incoming http requests on all available IP address -unassigned- or on individual IP address. And by this you need to configure your website with certain IP address. Ok IIS> Sites> Add Web site and we need to fill the Site Name, Path, and in the binding information are type your certain website. Keep the other option as the same.
This will add addional site in the IIS. The site configuration appears like this in the applicationHost.config file<site name="SiteBindingUsingIP" id="3">
<application path="/" applicationPool="SiteBindingUsingIP">
<virtualDirectory path="/" physicalPath="C:\SiteBindingUsingIP" />
<binding protocol="http" bindingInformation="172.20.2.193:80:" />
One disadvantage of this approach is that IP address is not always free to use. So assigning an IP address to every website may be a non eligible choice.
Using Custom TCP Port
We can change allow website to learn to a non-default TCP port rather than port 80 which is the default port of http protocol. What you need to do to accomplish this is the same of the previous step but you need to provide a unique and avail be TCP port. In the attached image the new site WebSite2 is using the same IP address of WebSite1 but on different port which 8080.
When users request the site they need to provide the TCP port after the name of the server or the IP address like this: http://sitename:PortNumber/ or http://IpAddress:PortNumber/. E.g. http://websit2:8080 or http://172.20.2.192:8080
The main disadvantage of this method is that the users need to know on which port the website is working and append the TCP port to the website address and this not eligible on all case.
Using Host Headers
HTTP Host: headers are a feature of the HTTP v1.1 specification that allows a web server to host multiple web sites on a single IP address and TCP port, while simultaneously allowing HTTP v1.1 clients to specify the web site they wish to connect to. The process requires that the client send a Host: HTTP header as part of the HTTP request specifying a web site it wishes to access, and the web server having a web site configured with a corresponding HTTP Host: header value.
Follow the same previous steps to define the website and fill the host header you need at the Host name field. You can change the TCP port but this will make no sense since host headers is enough to distinguish between websites on the same IP address.
One website can have multiple hosting headers you can add more host headers by adding more bindings with different host names. To edit the site bindings Choose the desired site > Edit Binding and you can add/edit/and remove bindings.
Clients could not be able to connect to the web server using host headers unless you those host headers are defined in the appropriate DNS Server or Host File. IIS is not a name resolution server its a web server so the mechanism how the users can contact your web server with the names you choose –host headers- is not the responsibility of the IIS server.
Host Headers and SSL
To use host headers with https a certain configuration should took a place. Until Windows 2003 SP1 IIS6 could not handle host headers over SSL. This is because that the host headers themselves are encrypted within the entire encrypted http request so when the http request is being received on the IIS it could not figure out to which website it should be redirected. After the SP1 IIS6 or by using IIS7 you can use wildcard certificates to handle host headers over https –we will not go throw this process in this post-
Hope this helps. In the next post we will have a look to Application Pool concept.