ASP.NET Core web application is actually a console project that starts execution.
Starting from the entry point public static void Main() in the Program class, we can create a Hosting web applications.public class Program{ public static void Main(string[] args){ BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<startup>() .Build(); }
WebHost is a static class that can be used to create instances of IWebHost and IWebHostBuilder with preconfigured default values.
CreateDefaultBuilder() Method creates a new instance of WebHostBuilder with preconfigured default values. Internally,
it configures Kestrel, IISIntegration and other configurations. The following is CreateDefaultBuilder() method.
When we want to host the application into IIS, we need to addUseIISIntegration()Method that specifies IIS as the external web server.
UseStartup
Build()The method returns an IWebHost instance, while the Run() method starts the web application until it stops.
The above is the detailed content of What is the purpose of the Program.cs file in a C# ASP.NET Core project?. For more information, please follow other related articles on the PHP Chinese website!