what’s the deal with sites, applications, and virtual directories?
Before you can serve a single request from your IIS7 server, you need to create a set of configuration that describes how the server listens for requests, and how these requests are then dispatched to your scripts or static files. To do this, you need to at minimum create a site, an application, a virtual directory, and an application pool, which together provide the basic configuration necessary to serve your website (to be fair, the default configuration of the server already includes a set of these that you can use right away – more on that later).
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.
A binding is a combination of protocol name and protocol-specific binding information. While IIS7 supports multi-protocol bindings (WCF’s soap-tcp, FTP, etc), we will focus on the http path only here. So, for our purposes an http binding effectively defines an http endpoint that listens on:
- A specific interface ip address (or all interfaces)
- A specific port number
- A specific http host header (or all host headers)
This way, you can configure many sites on your server that listen on different ip addresses, different ports, or on the same ip address / port but with different host headers.
It’s important to note that the url of the request has no part in determining which site the request is routed to – only the bindings do. All requests received on a binding are sent to the site that owns the binding, so effectively each site owns its own full url namespace starting with “/”.
This url namespace is then partitioned further into applications, and then further yet by virtual directories.
An application is a logical container of your website’s functionality, allowing you to divide your site’s url namespace into separate parts and control the runtime behavior of each part individually. For example, each application can be configured to be in a separate application pool, thereby isolating it from other applications by putting it in a separate process, and optionally making that process run with a different Windows identity to sandbox it. The application is also the level at which ASP.NET applications / appdomains are created.
Each application has a virtual path that matches the initial segment of the url’s absolute path for the requests to that application. A request is routed to the application with the longest matching virtual path.
- Each site must have at least the root application with the virtual path of “/”, so any requests not matching other applications in the site will be routed to the root application.
Finally, a virtual directory maps a part of the application url namespace to a physical location on disk. When a request is routed to the application, it uses the same algorithm to find the virtual directory with the longest virtual path matching the remainder of the request’s absolute path after the application path.
- Again, each application must have at least the root virtual directory with the virtual path of “/” to be functional.
Read more »
VN:F [1.7.2_963]
Rating: 5.0/5 (1 vote cast)