Unknown developer
Unknown developer

Reputation: 5970

How exactly an ASP. NET core web application is launched

I am developing an ASP.NET Core web application with Visual Studio 2017. After publishing the project (e.g. in Azure), I know that Main() method in Program.cs is invoked only the very first time we send an Http request to the corresponding server. Actually, that is when the application is launched. Every subsequent request does not invoke the above method. I have some queries upon the above:

Upvotes: 2

Views: 434

Answers (1)

Alexey Andrushkevich
Alexey Andrushkevich

Reputation: 6172

My guess is that launching is in fact running dotnet <app_name>.dll. Am I right?

Yes, you are right. IIS has the ASP.NET Core Module (ANCM) which is responsible for proxying requests from IIS to a backend ASP.NET Core application running Kestrel. So yes in fact it does call dotnet <your_app>.dll in the background when the application is started and the Main method is invoked once exactly at that time. Once the process is started IIS just proxying incoming requests to it.

How the subsequent requests know the application has already been launched? By which mechanism are they informed?

Not sure for 100% but I can guess that ANCM tries to connect to ASP.NET Core Application over HTTP and in case the remote app doesn't respond it just tries to run it with dotnet <your_app>.dll one more time.

How dotnet command is known to the remote server? Does the deployment care about that and copies the appropriate files to the server?

Yes. When you publish your ASP.NET Core application by running dotnet publish -o <publish_folder> note the web.config file that was created automatically on publish. This file is used to configure ANCM and provides it with information about <your_app>.dll and dotnet command.

This is going to change (ensuring forward and backward compatibility) with ASP.NET Core 2.1. For more information look at ASP.NET Core 2.1.0-preview1: Improvements to IIS hosting

Upvotes: 3

Related Questions