...

/

ASP.NET Core MVC Initialization

ASP.NET Core MVC Initialization

Learn about the default initialization and configuration of an ASP.NET Core MVC website, covering service registration, HTTP pipeline configuration, and starting the web server.

Appropriately enough, we will start by exploring the MVC website’s default initialization and configuration:

Step 1: Open the Program.cs file and note that it uses the top-level program feature (so there is a hidden Program class with a $ method). This file can be divided into four important sections from top to bottom. As we review the sections, we might want to add comments to remind ourselves what each section is used for.

Note: .NET 5 and earlier ASP.NET Core project templates used a Startup class to separate these parts into separate methods, but with .NET 6 and later, Microsoft encourages putting everything in a single Program.cs file.

Step 2: The first section imports some namespaces, as shown in the following code:

Press + to interact
// Section 1 - import namespaces
using Microsoft.AspNetCore.Identity; // IdentityUser
using Microsoft.EntityFrameworkCore; // UseSqlServer, UseSqlite
using Northwind.Mvc.Data; // ApplicationDbContext

Remember: By default, many other namespaces are imported using the implicit usings feature of .NET 6 and later. Build the ...