Saturday, 15 August 2015

ASP.NET Request Process in web server


When request come from client to the server, it has pass from different process and stages before sending response to the client.

What is the web server?
When we run our asp.net web application from VS IDE, VS integrated ASP.NET engine is responsible to execute all kind of asp.net requests and responses. The process “WebDev.Webserver. exe” which take care of all request of an web application which is running from VS IDE.
Now, the “web server” comes into picture when we want to host the application on a centralized location and wanted to access from any locations. Web server is responsible for handle all the requests coming from clients, process them and provide the responses.
Actually Web Server is Software that enables a website to be viewed using HTTP, and it allows resources (web pages, images, etc.) to be requested over the HTTP protocol.
Client request of some information (client)-> Server received the request(web server) -> process the request and end back to client.


What is IIS?
Internet information server – is one of the most powerful web servers from Microsoft that is used to host our asp.net web application. IIS has its own Asp.net process engine to handle the request. So when a request comes from client to server, IIs takes that request and process it and send response back to the clients.

We have two main Threads.
1.       Worker Process
2.       Application tool
                Worker process (w3wp.exe) runs the asp.net application in IIS. This process is responsible to manage all the request and response that are coming from clients. All the asp.net functionality runs under the scope of worker process. When a request comes to the server from a client worker process is responsible to generate the request and response.

                Application pool is the container of worker process. Application pools are used to separate sets of IIS worker processes that share the same configuration. Application pools enable a better security, reliability and availability for any web application. The worker process separates each application pool so that when any worker process or application is having an issue, other applications or worker processes are not affected. This makes sure that a particular web application doesn’t impact other web application as they are configured into different application pools.

Let’s understand the flow of request using following steps:
Steps 1 - Browser makes an Http request for a page
Steps 2 – The Web server receive the request - The Main task of web server receives the HTTP request and return requested resource in an HTTP Response.
                IIS decide how to handle request, and decision is made based on the configuration settings.  For example if the requested page extension is .aspx pages then request will be handled by asp.dll.

Steps 3 – Routed to respective Engine.
                Our case it is ASP.Net Engine and it is also referred as ASP.net Http Module. HTTP modules are classes that have the access to incoming requested. These modules inspect the request and sent to HTTP Handlers, and these handlers are endpoints whose roles to generate the output and send back to requesting browser. Different Asp.net uses different HTTP Handlers;  this is based on the “Machine.config” <httpHandlers> settings sections.  For example in ASP.net page the request is routed to PageHandlerFactory – this is a class of HTTP Hanlder factory and its job is to find the compiled class which will present the asp.net page that is being requested .

Steps 4- Generate output response to users -  specified Http handler will generate the output response and pass back to the HTTP Module and then IIS which then send back to the client.

Conclusion:
We knew how ASP pages are processed in web server. Request -> To IIS -> Respective pool -> worker process (to load the ISAPI Extension which will create an HTTPRuntime) -> HTTP Module and HTTP handler -> page life cycle starts.

No comments:

Post a Comment

Dotnet core Basic: Read appsettings value in application

How appsettings.json object is referenced into dotnet core application, with an example. Example: let say I have the functionality to downlo...