Sunday 17 January 2021

Part 4: Create Asp.Net Core project using VS and Program class in Asp.Net Core

#10 minutes of reading 


In this article I will show you creating Asp.Net core application using visual studio and will go through with Program class in Asp.Net core application. 

Let’s create new project using visual studio 2019 community version. Select ASP.NET Core Web application shown in below screen.

Provide meaningful name to your application in Project name Field

Make sure application Type is .Net Core and Asp.Net Core 3.1 shown in below screen.


 Project gets created with name provided in Project name field (Asp.NetCore_sample).

Run application, Hello World! text gets rendered on browser. When you create empty project template for Asp.Net core application and run the application it will show Hello Word! text same seen with previous blog of .Net CLI.

For Empty project template of Asp.Net Core application, two classes get created under root directory of project.

1.       Program

2.       Startup

Execution of Asp.Net Core application starts from Main method of program class. Asp.Net Core application is like console application.

 

Note: In console application execution starts from Main method of program class and Asp.Net core web application initially starts as console application and CreateHostBuilder method of Program class converts application into web application.

 

Host.CreateDefaultBuilder(args) : This method is responsible for all configuration related to application like set application root directory, loading of environment variables, command line args, appsetting.Json, logging, etc.

Press F12 on CreateDefaultBuilder method to view below screen with details what this method configured and returned.

Asp.Net Core is open source and community based all code available on GitHub.

ConfigureWebHostDefaults method of Prgram.cs class responsible for configuring Kestrel web server and configure it with your applications configuration.



Kestrel: Kestrel is default web server enabled for Asp.Net core application. It is Cross platform web server and support on Windows, Linux and Mac. ConfigureWebHostDefaults method in Program class responsible for configuring Kestrel web server for Asp.Net Core application.


Previous                                                                                                                                                 Next

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home