ASP.NET Core MVC Tutorial – Session 5 – Main Method & InProcess / OutofProcess Hosting

ASP.NET Core MVC Tutorial - Session 5

This session will cover Main method in Program Class and Startup Class and describe runtime process of a Web App. Also we will talk about hosting and will go into detail of InProcess and OutofProcess hosting.
If you look at Web App sample that was created in previous sessions (ASP.NET Core Empty) and its structure, described in detail during Session 3 of this tutorial series. You can realize that it is look like Console Application in previous version of ASP.NET, Actually ASP.NET Core WEB App is initially a Console Application that turn to Web App during runtime process. Below code is related to Program Class and Main method of our project.

Main Method

This is start point of ASP.NET Core Web App and when a Web App executed, Main method is called first. Main method call CreateHostBuilder method which you can see its code just immediately after Main method. Result of CreateHostBuilder is an abstract class (IHostBuilder) and execution of this method will create hosting environment for our web app based on predefined configuration. This process is occurred by calling CreateDefaultBuilder and ConfigureWebHostDefaults methods of Host Class and all of them are belongs to Microsoft.Extensions.Hosting namespace.
Moreover Startup class and its methods set HTTP request pipeline and services configuration that injected to our Web App hosting environment through this code webBuilder.UseStartup<Startup>();

Startup Class

This class contains two important methods, ConfigureServices and Configure. ConfigureServices as its name implies is responsible for configuring our web app serveries. Also Configure method is responsible for configuring HTTP request pipeline. If these concepts are not understandable right now, don’t worry, we will practically work with these methods during this tutorial and you can learn all the concepts during this course. Below code is related to Startup Class.

InProcess & OutofProcess Hosting

ASP.NET Core Web App could be hosted InProcess and OutofProcess. We can select InProcess hosting model when we want to deploy our Web App on IIS web server. In this situation, users send their request to IIS web server then IIS respond to user request based on web app response. This hosting model has higher performance in comparison with OutofProcess hosting. But Cross-Platform feature is not available in this hosting model and you can only deploy your web app on Microsoft IIS. The figure shows you InProcess scenario.

ASP.NEt Core Web App InProcess Hosting Model

But ASP.NET Core Web App hosting default is OutofProcess which support cross-platform feature. In this hosting model, Kestrel is hosted our ASP.NET Core Web App. Kestrel is an ASP.NET Core embedded web server, it is cross-platform and can be acting as edge web server. Your Web app can be hosted on Kestrel by itself. Also, Kestrel can be an internal web server, then another web server same as IIS, Apache or Nginx can be Reverse Proxy Server. This model of hosting as it has been expected, has less performance than previous described hosting models. Yet as you can implement several security layers on your Reverse Proxy Server and you can benefit from Load balancing through Reverse Proxy Server, this model could be considerable.

OutofProcess Hosting Model without  Reverse Proxy Server
OutofProcess Hosting Model without  Reverse Proxy Server

Implement InProcess & OutofProcess Hosting Model

InProcess and OutofProcess hosting can be set on Project File. During Session 4 of this tutorial series we discussed how you can edit Project file. Consequently, by adding this code <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> to the Web App Project file hosting model is set as InProcess and by removing this code or adding this code <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> to Project File your Web App hosting model will be changed to OutofProcess.

Moreover, debug profile and launcher setting can be review and modify on Project Properties, Debug Tab. Also, this information is available and editable in launchSettings.json file under Properties folder. Within this session’s video, we show you how you can add IIS profile and launch your Web App with IIS web server. Also, launching ASP.NET Core Web App with Visual Studio Command line is available in this video.
Furthermore, detail of practical InProcess and OutofProcess hosting model is discussed during the video. Last but not least, if you want to see launcher process name and you want to find what web server is hosted your web app, you can modify Configure method of Startup Class as shown below.

If you need more details, watch this session video. Also, for being updated about our coming sessions, follow us on Instagram, Facebook, Telegram or YouTube and be in touch with us here.

You can download this Session Slides form HERE

0.00 avg. rating (0% score) - 0 votes

Tags

0 0 votes
Article Rating
guest

0 Comments
Inline Feedbacks
View all comments