Tuesday 25 August 2020

ASP.NET Core InProcess/OutOfProcess hosting

InProcess Hosting in ASP.NET Core

When an ASP.NET core application is executed, the .NET runtime looks for Main() method which is the entry point for the application. The Main() method then calls CreateDefaultBuilder() static method of the WebHost class. 

This CreateDefaultBuilder() method performs several tasks like 

  1. Setting up the web server 
  2. Loading the host and application configuration from various configuration sources and 
  3. Configuring logging

An ASP.NET core application can be hosted InProcess or OutOfProcess. here we will discuss only InProcess.

With InProcess hosting, the application is hosted in the IIS worker process (w3wp.exe or iisexpress.exe). With InProcess hosting, there is only one web server and that is the IIS server that hosts our application.

InProcess hosting in ASP.NET Core

To configure InProcess hosting, add <AspNetCoreHostingModel> element to the app's project file with a value of InProcess

<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

When we create a new ASP.NET Core project using one of the available project templates, the project defaults to the in-process hosting model for all IIS and IIS Express scenarios.

In case of InProcess hosting, CreateDefaultBuilder() method calls UseIIS() method and host the app inside of the IIS worker process (w3wp.exe or iisexpress.exe). 

  1. From a performance standpoint, InProcess hosting delivers significantly higher request throughput than OutOfProcess hosting
  2. In the case of IIS, the process name that executes the app is w3wp and in the case of IIS Express it is iisexpress
  3. To get the process name executing the app, use System.Diagnostics.Process.GetCurrentProcess().ProcessName
  4. When we are run the project from Visual Studio it uses IISExpress by default. 
  5. IIS Express is a lightweight, self-contained version of IIS, optimized for application development. We do not use it for production. In production we use IIS.

Out of Process Hosting in ASP.NET Core

To configure an app for out-of-process hosting, set the value of the <AspNetCoreHostingModel> property to OutOfProcess in the project file (.csproj):

<PropertyGroup>
  <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>

In-process hosting is set with InProcess, which is the default value.

The value of <AspNetCoreHostingModel> is case insensitive, so inprocess and outofprocess are valid values.

Kestrel server is used instead of IIS HTTP Server (IISHttpServer).
For out-of-process, CreateDefaultBuilder calls UseIISIntegration to:

  1. Configure the port and base path the server should listen on when running behind the ASP.NET Core Module.
  2. Configure the host to capture startup errors.

There are 2 web servers - An internal web server and an external web server

  • The internal web server is Kestrel and the external web server can be IIS, Nginx or Apache.
  • With InProcess hosting, there is only one web server i.e the IIS that hosts the asp.net core application. 

Depending on how you are running the asp.net core application, the external web server may or may not be used. 

What is Kestrel

Kestrel is a cross-platform web server for ASP.NET Core. When we run a .NET Core application using the .NET Core CLI (Command-Line Interface), the application uses Kestrel as the web server. 

The .NET Core CLI is a cross-platform tool for developing .NET core applications. Using the CLI we can

  1. Create a new project, configuration file, or solution based on the specified template
  2. Restore the dependencies and tools required for a .net core project
  3. Build a project and all of its dependencies
  4. Run a project etc...

Reference: Click here

0 comments:

Post a Comment

Topics

ADFS (1) ADO .Net (1) Ajax (1) Angular (43) Angular Js (15) ASP .Net (14) Authentication (4) Azure (3) Breeze.js (1) C# (47) CD (1) CI (2) CloudComputing (2) Coding (7) CQRS (1) CSS (2) Design_Pattern (6) DevOps (4) DI (3) Dotnet (8) DotnetCore (16) Entity Framework (2) ExpressJS (4) Html (4) IIS (1) Javascript (17) Jquery (8) Lamda (3) Linq (11) microservice (3) Mongodb (1) MVC (46) NodeJS (8) React (11) SDLC (1) Sql Server (32) SSIS (3) SSO (1) TypeScript (1) UI (1) UnitTest (1) WCF (14) Web Api (15) Web Service (1) XMl (1)

Dotnet Guru Archives