Skip to content
All articles

ASP.NET web development: Core, Razor Pages and a first application

Laptop displaying CSS code beside a smartphone
Photo by Negative Space on Pexels

ASP.NET web development uses Microsoft’s web framework to build sites and applications with .NET. For a new page-focused project, ASP.NET Core Razor Pages offers a practical first route. Follow 5 steps: select the SDK, create a separate project, add a page, inspect its output and define the next boundary. The example is a fictional service notice, not a connected customer system.

Which ASP.NET approach should a first application use?

Start by separating current ASP.NET Core from an inherited application bearing the broader ASP.NET name. A tutorial for another framework generation is not automatically suitable for your project. Inspect the project file and target framework before copying configuration. This guide targets a .NET 10 Razor Pages project and the corresponding Microsoft documentation; it is not a migration recipe for an existing site.

Microsoft’s ASP.NET Core overview describes a framework for web applications and services using .NET and C#, supported on Windows, Linux and macOS. The choice is therefore not limited to a Windows desktop development workflow. Operating-system support still does not establish that a particular hosting account has the required runtime or configuration.

Razor Pages, controller-based MVC and Blazor organise user interfaces differently. Choose around the work the application performs and the skills of its maintainers. For this exercise, the task is simply to request a page and receive a readable service notice. There is no need to introduce a separate browser application, an API client, authentication and a database merely to demonstrate that task.

Microsoft’s Razor Pages concepts explain that the @page directive lets the page handle requests without a separate controller. A PageModel can hold its request-handling code. That division gives a beginner two concrete places to inspect: the page’s markup and the C# logic supplying its values.

Use Razor Pages here because the exercise is page-focused, not because it is universally preferable. A highly interactive interface or an existing controller-based system may justify another approach. Decide that through a representative task and a maintainable implementation, rather than through a generic claim that one framework is fastest or most secure.

How do you build a bounded first Razor Page?

Step 1: create a separate project

The .NET 10 starter tutorial documents the webapp template. On an authorised development machine with the .NET 10 SDK already available, first inspect installed SDKs. Use a fresh directory and check that ServiceNoticeDemo does not already exist. Do not use a force option against an existing project.

dotnet --list-sdks
dotnet new webapp -n ServiceNoticeDemo -o ServiceNoticeDemo --framework net10.0
cd ServiceNoticeDemo

Project creation and later builds may restore dependencies. These are instructions for a developer-controlled environment, not offline commands or a record of execution here. No SDK installation, package restoration, application start or HTTP request was performed while preparing this article. Do not interpret the sample below as a compiled or browser-tested application.

Step 2: inspect what the template supplies

Read the generated Program.cs before changing anything. Microsoft’s fundamentals guide explains that it configures services and the middleware request pipeline. Keep that generated configuration for this exercise. Do not paste a whole startup file from an older tutorial over a project created by a different SDK.

The starter tutorial places Razor pages in Pages, static assets in wwwroot, and configuration in appsettings.json. Keep private information out of public assets. This example needs no credentials or connection string. Adding a configuration key would not, by itself, create a secure storage or access-control design.

Step 3: add a fictional service notice

Create Pages/Notice.cshtml.cs only if it does not exist. The original example uses an explicit allowlist of fictional topic identifiers. It returns editorial sample messages, not service availability, a repair commitment or information from a business system.

using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ServiceNoticeDemo.Pages;

public class NoticeModel : PageModel
{
    public string Heading { get; private set; } = "Demo service notice";
    public string Detail { get; private set; } = "Choose a fictional topic.";

    public void OnGet(string? topic)
    {
        (Heading, Detail) = topic switch
        {
            "pump" => ("Pump example", "Fictional inspection note only."),
            "gauge" => ("Gauge example", "Fictional calibration note only."),
            null or "" => ("Demo service notice", "Choose a fictional topic."),
            _ => ("Unknown demo topic", "Use pump or gauge in this example.")
        };
    }
}

Create its companion Pages/Notice.cshtml:

@page
@model ServiceNoticeDemo.Pages.NoticeModel
@{
    ViewData["Title"] = "Fictional service notice";
}
<h1>@Model.Heading</h1>
<p>@Model.Detail</p>
<p>Demonstration content. No live service status is connected.</p>
<ul>
    <li><a href="/Notice?topic=pump">Pump example</a></li>
    <li><a href="/Notice?topic=gauge">Gauge example</a></li>
    <li><a href="/Notice">Reset selection</a></li>
</ul>

Keep @page as the first Razor directive. Microsoft documents the page/model filename pairing and the convention that a page’s location determines its route. Here, Pages/Notice.cshtml corresponds to /Notice. The @model line names the class containing the notice properties, so a namespace mismatch is a concrete place to investigate a compilation error.

OnGet supplies the values for a GET request. The sample does not echo the supplied topic into the response: it chooses one of four defined outcomes. That makes unknown inputs easy to reason about. It is not authorisation, validation for every future input, or a substitute for security review when real records are introduced.

Step 4: inspect the expected requests

An authorised developer can run dotnet build from the project directory, then dotnet run after a successful build. Use the local address printed by the application. HTTPS development certificates may need the platform-specific trust procedure described in Microsoft’s tutorial; do not disable certificate checking or alter shared server certificates to hide a local setup problem.

The following matrix is the original acceptance example. Its outcomes follow the proposed code and have not been observed in a running application here.

Requested path Expected heading Expected meaning
/Notice Demo service notice No topic selected
/Notice?topic=pump Pump example Defined fictional pump message
/Notice?topic=gauge Gauge example Separate defined message
/Notice?topic=other Unknown demo topic Unrecognised input gets a controlled response
/Notice?topic=PUMP Unknown demo topic Matching is deliberately case-sensitive

Inspect the returned page source as well as its appearance. The notice should be part of the server-rendered response, rather than depending on a later client script to insert it. Check the links with a keyboard. A successful compiler result would establish a different thing from a successful request, a usable page or an accessible journey; keep those observations separate.

If the page returns a not-found response, confirm its location, @page directive and generated Razor Pages mapping. If the heading is wrong, check the query value and handler. Do not change DNS, hosting or application permissions to investigate a mistake that is still within a disposable local example.

Step 5: preserve the learning boundary

Before turning this into a real service-status application, decide who owns the information, how it is updated and what users should see when the source is unavailable. A static fictional sentence must never become an implied operational assurance. Introducing sign-in, edits or persistence also introduces requirements absent from this example.

Keep deployment questions in the separate ASP.NET hosting guide. For the larger project brief, see web development or get started with the required pages and data responsibilities. Retain the request matrix alongside the code so a later change can explain which behaviour was intentionally altered.

By Spout Team. AI-assisted drafting by Codex using the linked Microsoft documentation.

Make your next move.

A website, a store or a clearer digital plan. Let’s start with your business.

Start your brief