Home > front end >  Understanding ASP.NET Core with Apache
Understanding ASP.NET Core with Apache

Time:09-17

In IIS we had an aspnet_isapi extension that handles the request, it then spawns a process w3wp.exe, w3wp.exe then loads and starts the CLR and then CLR does its job. Now, Kestral is configured inside the Main() method, so first the Main() should execute, so who starts the Core CLR ? is it IIS for windows and Apache for Linux? Do IIS and Apache know how to search and start Core CLR?

what I know is, When a .NET application is executed at that time the control will go to Operating System, the Operating System create a process to load CLR.

The program used by the operating system for loading CLR is called runtime host, which are different depending upon the type of application that is desktop or web-based application i.e.

The runtime host for desktop applications is an API function called CorbinToRuntime.

The runtime host for web-based applications is the ASP.NET worker process (aspnet-wp.exe). So, how is it possible that first the Main() method will execute and then the CLR, i am not able to digest it, please help.

CodePudding user response:

Forget about everything you know about IIS.

For Apache or nginx, just run your ASP.NET Core console application (who initializes Core CLR) at a local port (http://localhost:5000 for example), and then set up reverse proxy rules to forward external traffic to that port.

That's roughly what Microsoft documented in this article

Such reverse proxy setup is common, as other web stacks (Node.js, Python, Go) are using the same approach.

Because of this specific setup, Linux launches your .NET Core console app by analyzing the COFF envelope (of dotnet executable, or your own executable for self contained deployment) to locate the native entry (not your managed Main).

Apache/nginx is not involved in anyway.

Calling into this entry triggers CoreCLR initialization, and in turn your managed assemblies are loaded and managed Main is called.

You might find articles like this helpful.

  • Related