ASP.NET Core in-process hosting

bhavna 106 Reputation points
2022-02-16T09:59:21.27+00:00

When we use dotnet.exe <appname.dll> to run the dot net core apps or create a service file (systemd) then we mention dotnet.exe to start the app, which calls the hostfxr which finds the CoreCLR and start execution. With In-Process we don't use dotnet.exe, so how does ASP.NET Core module work internally?

The documentation says CreateDefaultBuilder adds an IServer instance (HttpServer) by calling the UseIIS method to boot the CoreCLR and host the app inside of the IIS worker process (w3wp.exe or iisexpress.exe). But how is this possible? CreateDefaultBuilder will be called when Main() will be called and CLR will start executing the Main(), then what is meant by boot the CLR? the CLR must be called before the Main() method is called, isn't it?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,505 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 64,001 Reputation points
    2022-02-16T18:29:24.307+00:00

    the AspNetCore module is C++ module that loads the core clr and calls main, similar to this:

    https://learn.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting

    the core module is also responsible for mapping IIS network I/O to the asp.net core pipeline. The builder called from main is responsible interfacing to the aspnetcore module or use Kestrel. These interfaces are also called hosts, and they have been re-architectured several times to more common. current docs of WebBuilder:

    https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/web-host?view=aspnetcore-6.0

    You can create a custom host that uses something besides Http packages, say recv / send to queue manager:

    https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/web-host?view=aspnetcore-6.0

    note: the aspnetcore module source:

    https://github.com/dotnet/aspnetcore/tree/a899ce80c36138df814b3258093a21de3ca95c5c/src/Servers/IIS


1 additional answer

Sort by: Most helpful
  1. Sreeju Nair 12,346 Reputation points
    2022-02-16T15:47:44.28+00:00

    When you host your .Net Core application, you will need to install ASP.Net Core Module/Hosting Bundle.
    Refer: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-6.0

    As per the documentation,

    The ASP.NET Core Module is a native IIS module that plugs into the IIS pipeline, allowing ASP.NET Core applications to work with IIS. Run ASP.NET Core apps with IIS by either:

    Hosting an ASP.NET Core app inside of the IIS worker process (w3wp.exe), called the in-process hosting model.  
    Forwarding web requests to a backend ASP.NET Core app running the Kestrel server, called the out-of-process hosting model.  
    

    Refer: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-6.0

    You can understand various web server implementations in ASP.Net Core from the below link

    https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/?view=aspnetcore-6.0&tabs=windows


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.