Tutorial :How iis recognize a web application?


I have been asked these question in interviews...

1.How iis recognize that which web application we are requesting?

2.How iis recognize that web application is developed in which language?

Can anyone explain them in detail...


I am not going to cover the territory of what a web application is because that is not your question, so throughout this answer I will use the terms web application or virtual directory interchangeably. If you want to know more about what a web application is on IIS, then this article from an official MS site on IIS: Understanding Sites, Applications, and Virtual Directories on IIS 7 will be of assistance. While the title does say IIS7, it also delves into IIS6.

What web application are we requesting

Keeping it simple, the request you make to the server has the virtual directory included in it, or IIS will already be configured to map the request to a specific virtual directory. If your requested URL looks like this:


then the myWebSite part of that url is the virtual directory and IIS knows exactly how to handle that because it is mapped directly to a folder on the file system. But like i said, that is just the simplistic approach, and is the one you are probably using to access your own web applications on your dev machine or on your company intranet. There is also another way to find the virtual directory from the url - with host headers. When you make a request to a (IIS based) website across the internet, it is most likely to be hosted on the same web server with dozens or even hundreds of other websites. In this case host header bindings are used to map the request to a specific web site / web application. You can read up about host headers work in this article: HOWTO: IIS 6 Request Processing Basics, Part 2 - Web Site, Virtual Directory, and Web Application.

Web application language

The language of the page is specified in the page itself (in the aspx or ascx file). Whenever the app pool worker processes are started for the first time, or recycled (restarted) the web pages are recompiled, the language specified in the page or control is used as the guideline as to which compiler to use. The compiled code is then kept in temporary storage until files get changed and a recompilation needs to take place or the worker processes are recycled again.

If it is precompiled then it is not necessary to know the page language because it has already been compiled to an intermediate language called MSIL (Microsoft Intermediate Language, or more correctly CIL, Common Intermediate Language), this code is then JIT compiled to native code before being executed. (JIT compilation: simple explanation, wiki explanation, slightly more hardcore explanation).

If the web application has been ngen compiled then it is already in a native machine language, and therefore needs no compilation at all.


Regarding question #1, IIS uses something it calls a metabase to track information about web applications it hosts, along with a host of other useful information. The IIS metabase keeps track of any node, be it an entire web site, or simply a child virtual directlry, that are marked as "applications". Each application can be hosted in an application pool...either individually, or many applications can share a single pool. IIS provides a variety of management options, including a WMI API, LDAP API, COM API's, and managed API's (which API's are available depend on the version of IIS...v7 includes some rich managed API's as well as extensive PowerShell support.)

To be perfectly honest, I don't think question #2 is even a valid question. IIS itself does not care what language something was written in, since IIS is not responsible for compiling anything. I think that indicates the interviewer does not have a firm grasp of the concepts him/her self. It is also possible the question was a trick question, with the correct answer being "IIS does not have the ability, nor need to know, the type of language a web application is built in, since IIS is not responsible for compilation of .NET web sites."

The ASP.NET worker process, on the other hand, IS responsible for compiling and executing ASP.NET applications. The language is usually identified by the @Page directive at the top of the file being processed. Compilation can either occur early, rendering the web site into a .dll assembly along with .aspx, .ascx, and any other handler files, or it can occur real-time, allowing a web site to be built dynamically. The latter requires that the ASP.NET runtime know the language of the page being compiled.


Simplified version:

IIS is able to plugin ISAPI extensions (like SSL filter, Compression filter, PHP, ASP.NET, ...).

1) IIS examines the requested URI and sends it to the extension that has that URI path registered.
ASP.NET registers *.ascx, *.ashx, *.aspx,... paths by default.
*.php paths are usually registered with PHP extension, etc.

2) Now ASP.NET receives it's first request and the ApplicationManager class creates an application domain and a HostingEnvironment object with informations and isolation for our application (based on the URI).

3) Core objects get initialized (Http* like HttpRequest, etc.)

4) A HttpApplication object is created.

5) Requests is processed and returns a response (if successful).

The 2 - 4 steps only happen once and those objects reside in memory waiting for other requests.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »