There are two ways to configure out-of-process hosting:

  • Method one: will<AspNetCoreHostingModel>Element is added to the application’s project file with a value ofOutOfProcess

<AspNetCoreHostingModel> OutOfProcess </AspNetCoreHostingModel >

  • Method 2: The default value isOutOfProcessHosting. So if we delete from the project file<AspNetCoreHostingModel>Element, which is used by ASP.NET Core by defaultOutOfProcessHosting.

Out-of-process hosting

  • There are two Web servers, the internal Web server and the external Web server.
  • The internal Web server is Kestrel, and the external Web server can be IIS, Nginx or Apache.

Depending on how you run your ASP.NET Core application, you may or may not use an external Web server.

Kestrel is a cross-platform web server embedded in an ASP.NET Core application. Using out-of-process hosting, Kestrel can be used in one of two ways:

Kestrel can be used as an Internet-facing Web server, processing incoming HTTP requests directly.

In this model, we do not use an external Web server. Using only Kestrel, it can face the Internet as a server and handle incoming HTTP requests directly. When we run an ASP.NET Core application using the. Net Core CLI, Kestrel is the only web server used to process and process incoming HTTP requests.

Kestrel can also be used in conjunction with a reverse proxy server such as IIS, Nginx, or Apache.

Use the following code to get the process name

Remember this line of code, which is a knowledge point

System.Diagnostics.Process.GetCurrentProcess().ProcessName;

When we run an ASP.NET Core project using the.net Core CLI, by default it ignores the managed Settings we specified in the.csproj file. Therefore, the value under ‘ ‘AspNetCoreHostingModel’ in the project file is ignored. Regardless of the value you specify (InProcess or OutOfProcess), it is always OutOfProcess managed, hosting the application through Kestrel and processing HTTP requests at the same time.

Q&A

If Kestrel can be used as a Web server alone, why do we need a reverse proxy server?

Because Kestrel uses “out-of-process hosting,” combining a reverse proxy server is a good choice because it provides an additional layer of configuration and security. It may be better integrated with existing infrastructure. It can also be used for load balancing.

Therefore, in the case of a reverse proxy server, it will receive incoming HTTP requests from the network and forward them to the Kestrel server for processing. As the request is processed, the Kestrel server sends the response to the reverse proxy server, which eventually sends the response over the network to the requesting client.

When we run an ASP.NET Core application directly from Visual Studio, it defaults to IIS Express. Since we have configured our application to use out-of-process hosting, IIS Express is already acting as the reverse proxy server in this case.

IIS Express receives incoming HTTP requests and forwards them to Kestrel for processing. Kestrel processes the request and sends the response to IIS Express. IIS Express, in turn, sends the response to the browser.

Using out-of-process hosting Whether or not you use a reverse proxy server, the Kestrel server processes requests simultaneously as a server for the hosted application, which is what we originally called self-hosting. If you use a reverse proxy server to receive incoming HTTP requests and forward them to the Kestrel server. Again, it gets the response from the Kestrel server and sends it to the client. So the process name hosting the application is dotnet.exe.

Can we run ASP.NET Core applications without using the built-in Kestrel Web server?

The answer is yes. If we use InProcess hosting, the application will be hosted in the IIS worker process (w3wp.exe or iisExpress.exe). Kestrel is not used with InProcess hosting.