Setting up WebHostBuilder
As in the last chapter, we will focus on Program.cs
in this section. WebHostBuilder
is our friend. This is where we configure and create the web host.
The following code snippet is the default configuration of every new ASP.NET Core web project we create using File | New | Project in Visual Studio or the dotnet new
command with the .NET CLI:
var builder = WebApplication.CreateBuilder(args); var app = builder.Build(); app.MapGet("/", () => "Hello World!"); app.Run();
As we already know from previous chapters, the default builder has all the necessary stuff preconfigured. All you require in order to run an application successfully on Azure or an on-premises IIS is configured for you.
But you are able to override almost all of these default configurations, including the hosting configuration.
Next, let's set up Kestrel.