Creating the Most Basic ASP.NET Core 8 Website
PART 1: Creating the Most Basic ASP.NET Core 8 Website
This tutorial begins with the smallest possible ASP.NET Core 8 website. Razor Pages, Bootstrap, Home and Privacy pages will be added progressively in later parts.
1. Check the .NET SDK
dotnet --version
The result should begin with 8, for example 8.0.412.
2. Create the project
mkdir mydotnet
cd mydotnet
dotnet new web -n basicdotnet --framework net8.0
cd basicdotnet
The command uses the web template deliberately. It creates a minimal ASP.NET Core application, not the more complete Razor Pages template.
3. Examine the initial structure
basicdotnet/
├── Properties/
│ └── launchSettings.json
├── appsettings.Development.json
├── appsettings.json
├── basicdotnet.csproj
└── Program.cs
There is no Pages directory yet because Razor Pages has not been enabled.
4. Examine the project file
Open basicdotnet.csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>
5. Examine Program.cs
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();
MapGet associates the root URL, /, with a response. app.Run() starts the web server.
6. Run the application
dotnet run
Open the address printed after Now listening on:. The browser should display Hello World!.
7. Change the message
Stop the server with Ctrl+C, then change the endpoint:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Welcome to basicdotnet");
app.Run();
Run dotnet run again and refresh the browser.
What has been achieved?
- A working ASP.NET Core 8 server
- One root route
- A plain-text response
The project still has no HTML structure, CSS, navigation, Privacy page or Razor Pages.
Next: PART 2 converts the plain-text response into a proper HTML page.