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
- Setting up the web server
- Loading the host and application configuration from various configuration sources and
- 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
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).
- From a performance standpoint, InProcess hosting delivers significantly higher request throughput than OutOfProcess hosting
- In the case of IIS, the process name that executes the app is w3wp and in the case of IIS Express it is iisexpress
- To get the process name executing the app, use System.Diagnostics.Process.GetCurrentProcess().ProcessName
- When we are run the project from Visual Studio it uses IISExpress by default.
- 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):
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:
- Configure the port and base path the server should listen on when running behind the ASP.NET Core Module.
- 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
- Create a new project, configuration file, or solution based on the specified template
- Restore the dependencies and tools required for a .net core project
- Build a project and all of its dependencies
- Run a project etc...
Reference: Click here
0 comments:
Post a Comment