

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the purpose of Program.cs file in C# ASP.NET Core project?
ASP.NET Core web application is actually a console project which starts executing from the entry point public static void Main() in Program class where we can create a host for the web application.
public class Program{ public static void Main(string[] args){ BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<startup>() .Build(); }
The WebHost is a static class which can be used for creating an instance of IWebHost and IWebHostBuilder with pre-configured defaults.
The CreateDefaultBuilder() method creates a new instance of WebHostBuilder with pre-configured defaults. Internally,
it configures Kestrel, IISIntegration and other configurations. The following is CreateDefaultBuilder() method.
- Sets the “Content Root” to be the current directory
- Allows Command Line args to be pushed into your configuration object
- Adds both appsettings.json and appsettings.{Environment}.json to be loaded into the configuration object
- Adds environment variables to the configuration object
- If in Development, allows the loading of secrets.
- Adds Console/Debug loggers
- Tells the app to use Kestrel and to load Kestrel configuration from the loaded config
- Adds Routing
- Adds IIS Integration
When we want to host our application into iis we need to add UseIISIntegration() method specifies the IIS as the external web server.
UseStartup<startup>() method specifies the Startup class to be used by the web host. we can also specify our custom class in place of startup.
Build() method returns an instance of IWebHost and Run() starts web application till it stops.
- Related Questions & Answers
- What is the significance of NonActionAttribute in ASP .Net MVC C#?
- What is ViewData in ASP .Net MVC C#?
- What is the use of ChildActionOnly attribute in ASP .Net MVC C#?
- What is the purpose of the testng.xml file?
- What is the purpose of the .gitignore file?
- Explain the purpose of the Program class in ASP.NET Core
- What are the three segments of the default route, that is present in ASP .Net MVC\nC#?
- Explain the purpose of the Startup class in ASP.NET Core
- How to determine if C# .NET Core is installed?
- How to use ViewBag in ASP .Net MVC C#?
- What is the purpose of System Programs?
- What is the purpose of System Calls?
- What is the purpose of Human Life?
- What is the purpose of any research?
- What is the purpose of Risk Management?