avatarFuji Nguyen

Summarize

What is Program.cs file in ASP.Net Core project?

In an ASP.NET application, the Program.cs file is the entry point of the application. It is a C# file that contains a Main method, which is the starting point of the application.

The Main method typically does a few things:

  1. It creates an instance of the web application’s host. The host is responsible for bootstrapping the application and setting up the necessary services and middleware.
  2. It calls the Run method on the host, which starts the web server and listens for incoming HTTP requests.
  3. It waits for the user to stop the application by pressing a key or issuing a command to terminate the process.

Here is an example of a Main method in a Program.cs file:

public static void Main(string[] args)
{
    var host = CreateHostBuilder(args).Build();
    host.Run();
}

In most ASP.NET applications, the Program.cs file is located in the root of the project directory. It is typically accompanied by a Startup.cs file, which contains the application's startup configuration. The Startup class is responsible for configuring the application's services and middleware.

Thanks for reading! Hope you found it useful. Want more? Hit the “Follow” button below my profile. With your support, I’ll keep creating awesome content for you. Have a great day ahead! — Fuji Nguyen

Technology
Net Core
C Sharp Programming
Recommended from ReadMedium