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.
We'll cover the following...
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 singleProgram.cs
file.
Step 2: The first section imports some namespaces, as shown in the following code:
// Section 1 - import namespacesusing Microsoft.AspNetCore.Identity; // IdentityUserusing Microsoft.EntityFrameworkCore; // UseSqlServer, UseSqliteusing Northwind.Mvc.Data; // ApplicationDbContext
Remember: By default, many other namespaces are imported using the implicit usings feature of .NET 6 and later. Build the ...