The Main() method uses WebHostBuilder(). It is use to build up the HTTP pipeline via webHostBuilder.Use() chaining it all together with WebHostBuilder.Build() by using the builder pattern. It is available within the Microsoft.AspNet.Hosting namespace.The purpose of the Build method is to build the required services and a Microsoft.AspNetCore.Hosting.IWebHost which hosts a web application.The web hosting environment uses Kestrel, a cross-platform web server. UseContentRoot specifies the content root directory to be used by the web host.UseIISIntegration configures the port and base path the server should listen on when running behind AspNetCoreModule. The app will also be configured to capture startup errors. WebHostBuilder uses the UseIISIntegration for hosting in IIS and IIS Express. UseStartup specifies the startup type to be used by the web host. The Startup class is the place where we define the request handling pipeline and where any services needed by the app are configured. The Startup class must be public. The Build and Run methods build the IWebHost that will host the app and start it listening for incoming HTTP requests.
Asked In: Many Interviews |