Before starting this article please go through the previous article of Main method in ASP .Net Core. In this article we will cover
- What is ASP .NET Core Hosting model ?
- What is InProcess hosting in ASP.NET Core?
- How to host ASP.NET Core Application using InProcess hosting Model?
- How does the InProcess hosting work in ASP.NET Core?
There are 2 types of hosting models in ASP.NET Core i.e InProcess Hosting and OutOfProcess Hosting. Earlier version of ASP.Net Core we have only one hosting model which is Out-of-process but after due to the performance enhancement InProcess Hosting Model is introduced.
How to Configure InProcess hosting in ASP.NET Core?
To configure the InProcess hosting for ASP.NET Core Web application there is only one simple setting, just add the <AspNetCoreHostingModel> element to the application project file with a value of InProcess as shown in the below image. To find the application project file, just right click on your application from the solution explorer and click on the “edit yourapplication.csproj” option.
When we create a new ASP.NET Core Web application by using any template, by default the project file is created with InProcess hosting which is used for hosting the application in IIS or IIS Express scenarios.
In case of InProcess hosting (i.e. when the CreateDefaultBuilder() sees the value as InProcess for the AspNetCoreHostingModel element in the project file), behind the scene the CreateDefaultBuilder() method internally calls the UseIIS() method. Then host the application inside the IIS worker process (i.e. w3wp.exe for IIS and iisexpress.exe for IISExpress).
From the performance point of view, the InProcess hosting model delivers significantly higher request throughput than the OutOfProcess hosting model. Why we will discuss this at the end of this article.
The process name that will be used to execute the application is w3wp in the case of IIS. Similarly, if it is IIS Express then the process name will be iisexpress.
To display the process name in the browser you need to use the System.Diagnostics.Process.GetCurrentProcess().ProcessName within the Startup as shown below.
When you run the application and you can see the result as;
OutOfProcess Hosting
OutOfProcess hosting consists of 2 web servers
- Internal web server
- External web server.
What is Kestrel
Kestrel is a cross-platform web server for ASP.NET Core. It is supported on all platforms and versions that .NET Core supports. It is included by default as internal server in ASP.NET Core. Kestrel can be used, by itself as an edge server i.e Internet-facing web server that can directly process the incoming HTTP requests from the client. In Kestrel, the process used to host the app is dotnet.exe.
When we run a .NET Core application using the .NET Core CLI (Command-Line Interface), the application uses Kestrel as the web server.
With the InProcess hosting model, there is only one web server i.e. the IIS. So, in the case of the InProcess hosting model, we do not have the performance penalty for navigating the requests between the internal and external web servers. This is the reason why the InProcess hosting model delivers significantly higher request throughput than the OutOfProcess hosting.
In next article we discuss Kestrel Web Server in detail.
Summary
Post a Comment