Welcome to the comprehensive guide that will walk you through the process of creating a project, adding a data model, configuring middleware, and running an example application in ASP.NET Core. This guide covers essential steps and concepts to help you get started with building web applications using the powerful ASP.NET Core framework.

The guide begins with the initial setup, including creating the project and configuring the HTTP port for your application. You’ll learn how to add a data model to your project, including installing necessary NuGet packages and creating the required classes.

  1. Creating the Project
    1. Creating the Project
dotnet new globaljson --sdk-version 6.0.401 --output WebApp
dotnet new web --no-https --output WebApp --framework net6.0
dotnet new sln -o WebApp
dotnet sln WebApp add WebApp
  1. Setting the HTTP Port in the launchSettings.json File in the Properties Folder
  1. Adding a Data Model
    1. Adding NuGet Packages to the Project
dotnet add package Microsoft.EntityFrameworkCore.Design –version 6.0.9
dotnet add package Microsoft.EntityFrameworkCore.SqlServer –version 6.0.9
dotnet tool uninstall –global dotnet-ef
dotnet tool install –global dotnet-ef –version 6.0.9
  1. Creating the Data Model
  • Create a new folder named Models and add to it a class file named Category.cs:
  • Add a class called Supplier.cs to the Models folder:
  • Add a class named Product.cs to the Models folder:
  • Add a file called DataContext.cs to the Models folder:
  1. Preparing the Seed Data
  • Add a class called SeedData.cs to the Models folder:
  1. Configuring Entity Framework Core Services and Middleware
  • Preparing Services and Middleware in the Program.cs File in the WebApp Folder:
  • Defining a Connection String in the appsettings.json File in the WebApp Folder:
  1. Creating and Applying the Migration
  • Creating an Entity Framework Core Migration:
dotnet ef migrations add Initial
  • Applying the Migration to the Database:
dotnet ef database update
  1. Adding the CSS Framework
  • Installing the LibMan Tool Package:
dotnet tool uninstall –global Microsoft.Web.LibraryManager.Cli
dotnet tool install –global Microsoft.Web.LibraryManager.Cli –version 2.1.175
  • Installing the Bootstrap CSS Framework:
libman init -p cdnjs
libman install bootstrap@5.2.1 -d wwwroot/lib/bootstrap
  1. Configuring the Request Pipeline
  • The Contents of the TestMiddleware.cs File in the WebApp Folder:
  • Adding a Middleware Component in the Program.cs File in the WebApp Folder:
  1. Running the Example Application
dotnet run