Introduction
This lesson is the starting point of the twenty-part ASP.NET Core MVC course. In later lessons, we will build a database-driven content management application with articles, categories, users, and an administration area. A reliable application is created not only by writing code, but also by defining requirements clearly and preparing a controlled development environment.
In this lesson, we will define the scope of the application we are going to build. Then we will prepare the .NET 8 SDK, Visual Studio or Visual Studio Code, SQL Server, and the basic MVC project template. By the end of the lesson, you will have a working project skeleton with the MVC folder structure and a foundation ready for the next lessons.
This course uses .NET 8 and ASP.NET Core MVC. When running the commands, keep the project name and target framework consistent with the examples.
1. Defining the real-world project and its requirements
Let us give our application the working name ContentHub. ContentHub will be a web application where administrators can publish content and visitors can read that content.
Scope of the first version
Instead of trying to build every feature at once, we will create a working foundation first. This approach reduces unnecessary complexity and allows us to add one new capability in each lesson.
- Administrators can create, edit, and delete content.
- Each item has a title, summary, body, publication date, and publication status.
- Content can be associated with categories.
- Visitors can view a list of published content and open individual details.
- The administration area will later be protected with authentication and authorization.
- Persistent data will be stored in SQL Server.
Functional and non-functional requirements
Functional requirements describe what the application does. Non-functional requirements describe how it should perform those tasks. For example, “an administrator must be able to add content” is a functional requirement. “Invalid data must be displayed with understandable error messages” relates to quality and usability.
| Requirement | Initial implementation decision |
|---|---|
| Content management | We will use MVC Controllers and Razor Views. |
| Data storage | We will use Entity Framework Core and SQL Server. |
| Validation | We will add model validation attributes and server-side checks. |
| Security | We will implement authentication, authorization, and secure form processing. |
| SEO | We will create meaningful URLs, titles, and metadata. |
This list can act as a project contract. Before adding a feature, evaluate whether it supports the application’s goal. This prevents a small content management application from becoming an uncontrolled and unnecessarily complicated project.
2. Understanding MVC architecture briefly
ASP.NET Core MVC separates an application into Model, View, and Controller responsibilities. The Model represents application data and business rules. The View produces the HTML shown to the user. The Controller receives HTTP requests, prepares the required data, and selects the appropriate View.
When a visitor opens /Home/Index, the routing system sends the request to the matching Controller and action method. The Controller can prepare a model and pass it to the View. The View uses Razor syntax to place that model into HTML. Because these responsibilities are separated, we can manage the user interface, data access, and request flow more easily.
Putting every business rule inside a Controller may seem convenient at first, but it creates maintenance problems over time. In later lessons, we will separate data access with services and Entity Framework Core. In this lesson, we will only create the basic skeleton and verify that MVC works.
3. Preparing the .NET 8 SDK and development tools
3.1 The difference between the .NET SDK and runtime
The .NET SDK contains the compiler, .NET CLI tools, project templates, and components required to develop applications. The runtime is used to run an already-built application. Because we will develop a project, the SDK must be installed.
Install the .NET 8 SDK package appropriate for your operating system from Microsoft's official download page. After installation, open a new terminal and run:
dotnet --versionThe output should begin with 8. If multiple SDKs are installed, the following command lists them:
dotnet --list-sdksIf the command is not found, close and reopen the terminal. If the problem remains, verify that the SDK installation directory has been added to the system PATH variable.
3.2 Choosing Visual Studio or Visual Studio Code
On Windows, Visual Studio 2022 with the ASP.NET and web development workload is a comprehensive choice for beginners. Visual Studio provides an integrated experience for project creation, debugging, NuGet package management, and SQL-related tooling.
If you prefer a lighter and cross-platform environment, you can use Visual Studio Code. In that case, install the C# development extensions and the .NET SDK separately. Because we will create the project with the .NET CLI, either editor can be used in this course.
4. Preparing SQL Server
In later lessons, ContentHub data will be stored in SQL Server. For local development, you can use SQL Server Developer or SQL Server Express. Developer Edition provides a broad feature set for development and testing, while Express is a free option with more limited resources. Production licensing requirements must be evaluated separately.
In the SQL Server setup wizard, select the database engine component. After installation, note the connection type and instance name. In a default installation, the server name may be localhost or localhost\SQLEXPRESS. The exact value depends on your installation choices.
SQL Server Management Studio is a separate tool for managing databases visually. It is not required, but it is useful for inspecting tables, running queries, and testing connections. If you use Linux or macOS, you can run SQL Server locally or through a Docker-based setup and manage it with Azure Data Studio or another SQL client.
We will not create a database in this lesson. However, verify that SQL Server is running and that your connection details are available. When we reach Entity Framework Core migrations, we will configure the connection string safely.
5. Creating the MVC project with the .NET CLI
Create a folder for your projects and open a terminal in that folder. The following command creates a new ASP.NET Core MVC project named ContentHub:
dotnet new mvc -o ContentHub --framework net8.0Move into the project directory and build the application:
cd ContentHub
dotnet buildOn macOS or Linux, use a forward slash as the directory separator when necessary:
cd ContentHubThe dotnet build command compiles the project. A successful build should complete without error messages. The first build may take longer because NuGet packages need to be restored.
Start the application with the development server:
dotnet runThe terminal displays an address in the form http://localhost:xxxx. Open that address in a browser. If you see the default MVC home page, the basic project is working. Press Ctrl+C in the terminal to stop the application.
6. Examining the project structure
The generated project contains the following important folders and files:
Controllers: Controller classes that handle HTTP requests.Models: A folder for application models and ViewModel classes.Views: Razor View files.Views/Shared: Shared layouts and partial files used by multiple Views.wwwroot: CSS, JavaScript, and other static files.Program.cs: Service registration and HTTP pipeline configuration.appsettings.json: Configuration values that are independent of a specific environment.ContentHub.csproj: Target framework, packages, and project settings.
Open Program.cs and you will see the MVC services and default route configuration. Do not change this file yet. In later lessons, we will register the database context, dependency injection services, and security middleware here.
7. Making the first small customization
To verify that the project belongs to you, change the main heading in Views/Home/Index.cshtml:
<h1 class="display-4">Welcome to ContentHub</h1>
<p>This is the starting page of our content management application.</p>Save the file and run the application again. If you see the new text in the browser, the View change was applied correctly. If the heading does not appear, make sure you edited the correct file and opened the correct project folder.
Common mistakes
- Installing only the runtime: If
dotnet newordotnet buildfails, verify that the SDK is installed. - Selecting the wrong target framework: Confirm that the project targets
net8.0. - Running commands in the wrong directory: Run
dotnet runin the folder containing the.csprojfile. - Assuming the port is fixed: The development server may use a different port each time. Use the address shown in the terminal.
- Expecting SQL Server to be used immediately: This lesson prepares the environment. The connection string and migrations will be covered later.
- Using production settings during development: Use local development settings and never place passwords directly in source code.
Practice exercise
Complete the following short exercise:
- Create the
ContentHubproject and rundotnet buildsuccessfully. - Start the application and open the default home page in a browser.
- Edit
Views/Home/Index.cshtmland add two sentences describing the purpose of the application. - Write down the purpose of the
Controllers,Models,Views, andwwwrootfolders in your own words. - Record the server name of your SQL Server installation, but do not add a connection string to the application yet.
Conclusion
In this lesson, you defined the goal of the ContentHub application, reviewed the basic responsibilities of MVC, and created a working ASP.NET Core MVC project based on .NET 8. You also prepared the development editor and SQL Server environment.
In the next lesson, we will examine the MVC request flow in more detail and build practical examples involving Controller action methods, routing, and the relationship between Controllers and Razor Views. The working skeleton created in this lesson will become the foundation for every feature in the rest of the course.
Sources
- https://learn.microsoft.com/en-us/aspnet/core/mvc/overview?view=aspnetcore-10.0
- https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/start-mvc?tabs=visual-studio&view=aspnetcore-9.0
- https://learn.microsoft.com/en-us/dotnet/core/install/windows
- https://learn.microsoft.com/en-us/sql/database-engine/install-windows/install-sql-server-from-the-installation-wizard-setup