Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / IIS

IIS - Still Learning!

3.00/5 (1 vote)
19 Dec 2012CPOL7 min read 13K  
Learning about IIS

Whenever we receive some error which is related to IIS, we just jump on the internet as we lack the basic concepts of IIS and I can definitely say that we almost ignore IIS and focus on development and coding. Then why not learn IIS today? I would share my knowledge and request all of you to share your bit or you can send your articles/abstracts to admin@codepsread.com also.

What is IIS?

IIS - Wikipedia says “Internet Information Services (IIS) – formerly called Internet Information Server – is an app server application and set of feature extension modules created by Microsoft for use with Microsoft Windows.” Just check out the terms, application, set of feature extension modules, this means it is a program or component running on a Windows platform which provides us all the features or additional features required to host our website.

In the real world, a regular machine running a Windows server operating system is equivalent to a ‘server’ and if IIS is installed on this server and sites are hosted on IIS, then this server will be equivalent to web server. Simple enough!

It is a Microsoft product so it is tightly coupled to Windows platform and second, it was targeted to compete in Internet server market with already existing giants like Apache, so it has captured all the existing features and provided additional features also.

What is the Role of IIS?

Role is played by a character in a story, IIS is our character here, and the story is Application Life Cycle. In this story, there are many characters and IIS is the first and major character which plays host to any request coming to it and sends it to the processing pipelines.

Request sent by client | Request received by II

The figure shows communication of client and server over HTTP, server receives requests on Port 80 and if the protocol is HTTPS, port will be 443. Although I have skipped the DNS part, we will cover it sometime in the future.

How IIS Looks Like?

Go to Windows->Run->type inetmgr [Before that, check whether IIS is installed or enabled on your system. Refer to this article.]

IIS-Panel

IIS Panel has three groups: ASP.NET, IIS and Management. Out of these 3, two are visible in the above image.

  • ASP.NET includes tasks related to managing tasks related to ASP.NET like connection strings, SMTP email, etc.
  • IIS includes tasks related to managing sites and applications like Modules, Handlers, etc.
  • Management includes tasks related to configuring administrative roles, delegation, and remote administration.

How It Works?

Once the request is received by IIS, it follows the below process:

  • IIS runs a process, inetinfo.exe, which processes the request as per its state like static or dynamic. Request for static resources, for example: HTML pages, Images, JavaScript files, XML will be directly handled by the server and sent back as a response. This process is quite fast also.
  • Request for Dynamic resources like web pages (.aspx), custom extensions, web service (.asmx), handlers (.ashx), global asax (.asax) files will require additional processing, which will be done by ISAPI extensions, where ISAPI stands for Internet Server Application Programming Interface. ISAPI extensions are filters which requires relation between ISAPI filter and files extension, that is, when a request for such a file arrives, IIS handles it to the corresponding ISAPI filter. For example: When a request for .aspx arrives, then IIS looks for the mapping of “aspx” extension which is mapped to “aspnet_isapi.dll” and hence requests for an aspx page to IIS will be given to aspnet_isapi extension. Another example is when a request for .asmx arrives, then IIS looks for the mapping of “asmx” extension which is also mapped to “aspnet_isapi.dll” and hence requests for an asmx page to IIS will be given to aspnet_isapi extension.
  • Request is passed to .NET runtime, where a lot of important things happen. For the very first request, ApplicationManager creates an application domain. Application domains provide isolation between applications for global variables, and allow each application to be unloaded separately. [MSDN]
  • ApplicationManager manages already running requests in the pipeline processing and routing any new request coming in to the new AppDomain.
  • Within an application domain, an instance of the class named Hosting Environment is created, which provides access to information about the application such as the name of the folder where the application is stored.[MSDN]. This can be appropriately understood as the playground for all the execution.
  • After that, ASP.NET creates and initializes core objects such as HttpContext, HttpRequest, and HttpResponse. The HttpContext class contains objects that are specific to the current application request, such as the HttpRequest and HttpResponse objects. The HttpRequest object contains information about the current request, which includes cookies and browser information. The HttpResponse object contains the response that is sent to the client, which includes all the rendered output and cookies.[MSDN]
  • The application is started by creating an instance of the HttpApplication class. If the application has a Global.asax file, ASP.NET instead creates an instance of the Global.asax class that is derived from the HttpApplication class. It then uses the derived class to represent the application.[MSDN]

Note: The first time that an ASP.NET page or process is requested in an application, a new instance of the HttpApplication class is created. However, to maximize performance, HttpApplication instances might be reused for multiple requests.

Once HttpApplication pipeline is ready, request goes through a number of events and developer has more control then.

What We Have Not Discussed?

There are few items which require more attention and were not included in above flow to make it simple.

Worker Process: Worker Process normally referred to as w3wp.exe is responsible for running ASP.NET application in IIS. The worker process does the real handling, delivery, and response to the incoming request for a particular Web site. This process is responsible for managing all requests and responses that are coming from the client system. Each website is associated with a worker process.

Application Pool

We can see in the above image, on the left hand side, we have Application Pools and Sites available. Each Web site runs in an application pool, which is a named worker process and logical memory allocation which can contain one or more websites or applications. Application pools provide isolation between sites and applications from each other. In other words, Application pools can be termed as an individual sets of IIS worker processes which ensures security and reliability. If there is an issue with a particular application pool, then it would not affect other websites running in a different application pool.

Application Pool Identities

Each worker process and associated application pool runs in the security context of an application pool identity. The default identity for both default application pools is Network Service. The identity is a user or service account used to run the worker process and application pool. We do have an option to select the identities but one error we regularly see is due to running the application under local user identity so the solution is to add it to the IIS_IUSRS group, which assigns the necessary permissions and privileges to allow the account to function as an IIS application pool identity.

Managed Pipelines

There are two managed pipeline mode available for processing requests of ASP.NET applications:

  • Classic
  • Integrated

When classic mode is selected, IIS processes the requests in an application pool by using separate processing pipelines for IIS and ISAPI. This means that the ASP.NET request pipeline is separate from the Web server pipeline. Modules apply only to requests that are routed to the ASP.NET ISAPI extension. If the file-name extension of the requested resource type is not explicitly mapped to ASP.NET, ASP.NET functionality is not invoked for the request because the request is not processed by the ASP.NET runtime.[MSDN]

When Integrated mode is selected, IIS processes the requests in an application pool by using single processing pipeline for IIS and ISAPI. The integrated pipeline receives a request and the request passes through stages that are common to all requests. For example, even though the .htm file-name extension is not explicitly mapped to ASP.NET, a request for an HTML page still invokes ASP.NET modules. This enables us to take advantage of ASP.NET authentication and authorization for all resources.[MSDN]

There are so many features or options available in IIS which I always wanted to learn, we will learn most of these features in subsequent articles.

Related Posts

  1. IIS Pre-Article
  2. Creation of DemoSpace

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)