MVC Core Bootstrapping, Kestrel Web Server and Request / Response process : Part II

Rohit Patil
5 min readMay 28, 2020

--

Hello Developers, In this article we are going to learn about Bootstrapping, Kestrel web Server and Request Response process of MVC Core.

ASP .NET Core MVC

So first i am going to create first ASP .NET Core MVC Web Application. After creating the application default project structure will be created.

Lets See Folder Structure of our created Project:

Folder Structure of .NET Core MVC Application

We can see above figure created lots folders and files. we can see above Controllers, Models and Views folders will be created.

In Controllers folder we add controllers, if we want to add UI we put into the Views folder, If we want to add classes of Models we add into Models folder.

So lets see Bootstrapping process of MVC Core application.

MVC Core Bootstrapping process :

Program.cs is the file which is runs first in MVC Core application and this file starts the web server means this file invokes the web server.

So first we understand what is Web Server ?

Web Server is an application which accept HTTP request and sent it back the appropriate response to the client.

HTTP Request and Response

For example, Two computers connected in network and that two machines when communicating with each other they use some protocols like HTTP, UDP, TCP and etc. If we create a website application here we use HTTP protocol for communicating. if we request any page to Server that accept this request, parse this and send back response to the browser. For Completing this process we require software application that do all this things.That software application we can call Web Server. for example, IIS, Apache, Nginx, Kestrel and etc.

Kestrel Web Server :

Kestrel is a Open source, cross platform and used as default web server in ASP .NET MVC Core application. It is developed by Microsoft. It was specially developed for the ASP .NET MVC Core applications.

It’s works on reverse proxy platform means it is deals with request and response.

Kestrel with reverse proxy server

If get any request from browser or internet to application they hit to the IIS web server, and they forward request to the Kestrel web server. Kestrel knows about MVC core. they sends back response to the IIS server.

Kestrel

If we want to see the server of any website we want to run the website and hit the press F12 and we can see the server. In my web application Kestrel is the server.

This is all about the Program.cs. Then Program.cs file invokes Startup.cs file.

Startup.cs:

Startup.cs file loads the initial configurations. Stratup.cs does the two things. First it goes and loads it Configuration and Second it loads the ConfigureServices. Configurations are all stored in appsettings.json file. All configurations in appsettings.json file was loaded into in Startup.cs file’s IConfiguration object.

Startup.cs file

We can see in above figure Startup.cs file has three methods. Startup.cs file loads the Configuration of that application.

Which three methods we can see :

  1. Constructor
  2. ConfigureServices
  3. Configure

Constructor : In Constructor loads Configurations using dependency injection.

Constructor of Startup Method

ConfigureServices :

In ConfigureServices we add Services.

ConfigureServices Method

In above figure we can see the Services.AddMvc() this service we will added in ConfigureServices method.

Configure :

In Configure we Configure Services which we added into the ConfigureServices method.

Configure Method

In above figure we can Configured that Srvice which will be added into the ConfigureServices method.

Configure and ConfigureServices this two methods will help us to define which service we want to use and how we want to configure.

Request-Response process :

When end user starts the application then first loads Controller because we configure set default route as ‘HomeController’ and Action means which view or UI gets loaded first we set into the ‘Index()’.

HomeController.cs

If user starts the appliication HomeController will started and in that method we set Action Index() will return which view we will be shown on browser.

For more information please visit this video for better understanding about MVC

Step by Step Learning ASP .NET Core MVC

  1. “Overview of .NET Core : Part I ”

2. “MVC Core Bootstrapping, Kestrel Web Server and Request / Response process : Part II ”

3. “HTTP Request, HTTP Response, Context and Headers : Part III”

In this article we learn about Bootstrapping, Kestrel web Server and Request - Response process of MVC Core.

Thanks for reading this article !!!…

--

--