Lesson 2 of 10

Understanding the Blazor Project Structure

Explore Program.cs, Components, Pages, Layout, routing, static files, and the key files in a modern Blazor Web App.

Visual Studio 2026.NET 10Beginner friendly

Before writing larger applications, you should know where the important files live. A Blazor Web App is an ASP.NET Core application whose UI is composed from Razor components.

1. Important folders and files

ItemPurpose
Program.csStarts the ASP.NET Core application, registers services, and configures endpoints and render modes.
Components/App.razorThe root component for the application.
Components/Routes.razorHandles component routing in the standard template.
Components/PagesContains routable pages such as Home, Counter, and Weather.
Components/LayoutContains shared layouts and navigation UI.
wwwrootStores static files such as CSS, images, and JavaScript.
appsettings.jsonStores application configuration.

2. Look at Program.cs

When Interactive Server components are enabled, a typical modern configuration contains calls similar to the following:

using BlazorTutorialApp.Components;

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddRazorComponents()
    .AddInteractiveServerComponents();

var app = builder.Build();

app.UseHttpsRedirection();
app.UseAntiforgery();
app.MapStaticAssets();

app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode();

app.Run();
Do not worry about memorizing Program.cs yet.

For now, notice that services are registered before builder.Build(), and the application pipeline/endpoints are configured afterward.

3. Page components and regular components

A component becomes directly reachable by URL when it contains an @page directive:

@page "/about"

<h3>About This App</h3>
<p>This is a routable Blazor page.</p>

A reusable component doesn't need an @page directive. It can be embedded inside another component using its component name as a tag.

4. Create an About page

Right-click Components/PagesAddRazor Component. Name it About.razor and paste:

@page "/about"

<PageTitle>About</PageTitle>

<h1>About</h1>
<p>I am learning Blazor with Visual Studio 2026.</p>

Run the application and browse to /about.

Try it yourself

Create Components/Pages/Contact.razor with the route /contact and display a heading and short paragraph.