To develop a webpage with ASP.NET, pick the right model first: use Razor Pages or MVC with ASP.NET Core for most new sites, and reach for Blazor only when you need rich, interactive client behavior inside C#. Then install the .NET SDK, scaffold a project from a template, replace the sample markup and logic with your own page, and run it locally before you deploy. The rest of this guide walks through that sequence in order, with checks at each stage so you can tell whether a step actually worked.
One clarification up front: "ASP.NET" in casual use covers two eras. Classic ASP.NET (.NET Framework, typically Web Forms or MVC 5) still runs plenty of internal business apps, but it only builds on Windows and receives no new feature work. Modern ASP.NET Core is cross-platform, actively developed, and the default for new projects. This article targets ASP.NET Core; I'll note where the classic path differs so a legacy maintenance task doesn't send you down the wrong road. The examples assume a current Long Term Support release, and version-specific command details are the one thing you should confirm against Microsoft's documentation for the exact SDK you install.
Choose your page model: Razor Pages, MVC, Blazor, or the legacy options
The single biggest decision happens before you type a command, because it determines your file layout, your mental model, and how much JavaScript you'll write. Each option optimizes for a different shape of problem.
| Model | Best fit | Page structure | Interactivity model |
|---|---|---|---|
| Razor Pages | Page-focused sites, forms, CRUD screens | One .cshtml page plus a paired PageModel class | Server round-trips, small amounts of JS |
| MVC | Apps with many shared layouts, APIs, complex routing | Controllers plus views plus models, separated | Server round-trips |
| Blazor (Server or WebAssembly) | Highly interactive UIs written in C# | Component tree (.razor files) | Reusable components, event-driven, no full reload |
| Web Forms (classic) | Maintaining existing .NET Framework apps | .aspx pages with controls and code-behind | Postbacks and view state |
| MVC 5 (classic) | Maintaining existing .NET Framework apps | Controllers, views, models | Server round-trips |
Razor Pages is the shortest path for "I need a webpage that shows data and handles a form." A page lives at a URL that mirrors its file path: Pages/Contact.cshtml serves /Contact by default. Logic goes in Contact.cshtml.cs, a class deriving from PageModel with handler methods like OnGet and OnPost. That pairing keeps markup and behavior in the same folder, which is why Microsoft recommends Razor Pages as the default for new page-based apps.
MVC splits the same work into three roles: a controller receives the request, a model carries data, and a view renders HTML. The separation pays off when many pages share layouts and when the same data feeds both browser views and JSON endpoints. The cost is more moving parts for a small site.
Blazor changes the interactivity story. Components are C# classes with Razor markup, and events like button clicks run C# methods rather than JavaScript handlers. Blazor Server keeps component state on the server and talks to the browser over a persistent connection; Blazor WebAssembly ships the .NET runtime to the browser and runs components client-side. If your page is mostly static content with a contact form, Blazor adds machinery you don't need. If you're building something closer to a desktop app in the browser, it saves you a JavaScript layer.
Web Forms and MVC 5 belong to the .NET Framework lineage. Web Forms' control-and-postback model and ViewState made rapid form building easy in the 2000s, but it produces heavier pages and couples markup tightly to server controls. Keep them for maintaining existing applications, not greenfield work. Notably, you can't open a Web Forms project in modern Visual Studio versions without the older workload, and the .NET Framework tooling is Windows-only.
A quick decision rule: a marketing site or a small internal tool with forms points to Razor Pages; a large app with distinct API and UI concerns points to MVC; a page that must feel app-like in the browser points to Blazor. You can mix models in one application, so this isn't irreversible, but migrating later costs real time.
Install the tooling and verify the SDK before you scaffold
Prerequisites come before any command. You need the .NET SDK, which bundles the runtime, the command-line tools, and the project templates. Download the current LTS release from Microsoft's official .NET site. LTS releases get three years of support, which is the safer baseline for anything you'll maintain.
Also install an editor. Visual Studio (Windows or Mac) offers the deepest ASP.NET integration; Visual Studio Code with the C# Dev Kit extension is lighter and cross-platform; JetBrains Rider is a paid alternative that many teams prefer. Any of them works, because the SDK does the real work and the editor is a convenience layer.
After installing, verify from a terminal:
The output should list your SDK version, the runtime versions, and the base path. If the command isn't recognized, the SDK isn't on your PATH: reopen the terminal so it picks up the new environment variables, and on Windows confirm the installer finished rather than sitting in a pending-reboot state.
Two success checks matter here. First, dotnet --list-sdks should show the version you intended. Second, run dotnet new list to confirm the templates are registered; you should see webapp, mvc, blazor, and webapi among the options. If templates are missing, the SDK install is incomplete.
A version detail worth flagging: template names, target framework monikers like net10.0, and default package versions all shift between releases. If a command in this article doesn't match what your SDK accepts, run dotnet new webapp --help to see the actual options for your installed version rather than guessing.
Scaffold a project and understand the files the template creates
With the SDK in place, create the project and get it running before changing anything. The principle is to confirm the template works untouched, so any later breakage is clearly yours.
1: Open a terminal in the folder where you keep code. 2: Run dotnet new webapp -n MyFirstSite -o MyFirstSite. The -n flag sets the project and assembly name; -o sets the output folder. For MVC use dotnet new mvc -n MyFirstSite; for Blazor WebAssembly use dotnet new blazorwasm -n MyFirstSite. 3: Change into the folder: cd MyFirstSite. 4: If the template includes a database context for individual accounts—the Razor Pages template with authentication does—apply migrations before first run with dotnet ef database update. Templates without authentication skip this. 5: Start the app: dotnet run. 6: The console prints the listening URLs, typically an and an pair. Open the HTTPS one.
You should see the template's home page render with styling. In Razor Pages you'll find these pieces:
Program.cs builds the application host, registers services, and configures the request pipeline with middleware. Pages/ holds the pages. Index.cshtml is the home page, Privacy.cshtml a sample secondary page, Shared/_Layout.cshtml the common shell, and _ViewImports.cshtml and _ViewStart.cshtml set up shared directives and defaults. wwwroot/ is the web root. Static files here—CSS, images, JavaScript—are served directly at the site root. The bundled template uses Bootstrap, which is why the page looks styled. appsettings.json stores configuration like connection strings and logging levels, with per-environment overrides in appsettings.Development.json. The .csproj file lists the target framework and package references.
If dotnet run fails, read the first error rather than the last. The usual causes are a target framework the installed SDK doesn't support (check that the .csproj's matches an SDK you have) or a build error in generated code after a template mismatch. Deleting the bin and obj folders and running dotnet build again resolves most stale-build puzzles.
Build your first real page: markup, models, and handlers
A working sample proves the toolchain; a real page proves you understand it. Here's a complete Razor Pages example for a simple contact form that validates input and confirms submission. It's deliberately small, but it contains every piece a production page needs: routing, binding, validation, and a post-redirect-get flow.
First, the page model, Pages/Contact.cshtml.cs:
Then the view, Pages/Contact.cshtml:
What each part does: @page turns the file into a routable Razor Page. [BindProperty] tells the framework to populate Input from form fields on POST. Data annotation attributes like [Required] and [EmailAddress] produce both server-side and client-side validation without hand-writing rules. The asp-for, asp-validation-for, and asp-validation-summary tag helpers generate the right name, id, and validation attributes. And ModelState.IsValid gates the handler so invalid submissions redisplay with error messages.
Run it and check three behaviors. Navigating to /Contact shows the empty form. Submitting with an empty name redisplays the page with a validation message and no new record. Submitting valid values shows the confirmation and a cleared form. If the POST returns a 400 instead of the page, the usual cause is a missing antiforgery token; tag helpers inject it automatically in forms, so that symptom typically means the form markup bypassed tag helpers.
For a page that writes to a database, the pattern extends naturally: inject your EF Core DbContext into the PageModel constructor, write in OnPostAsync, and either redirect to a success page with RedirectToPage or redisplay with Page(). The post-redirect-get pattern using RedirectToPage prevents duplicate submissions when someone refreshes after posting.
Add data access without letting page code sprawl
Most real pages read or write a database, and the clean way to do that in ASP.NET Core is Entity Framework Core with dependency injection. The mechanics are short; the discipline is what matters.
Register a context in Program.cs:
Define the context and a simple entity:
Create the schema with migrations rather than hand-edited SQL:
1: Install the EF Core tools if you haven't: dotnet tool install --global dotnet-ef. 2: Add a migration: dotnet ef migrations add InitialCreate. 3: Apply it: dotnet ef database update.
Check success by querying the table in your database client; the migration history table plus your new Products table should exist. If dotnet ef isn't recognized, the global tool path isn't on your PATH—check the tools folder (on Linux and macOS it's typically ~/.dotnet/tools).
Then inject the context into a page model and query in OnGetAsync:
Then render the list with a @foreach in the view. Two habits keep this from curdling: keep queries in the page model or a service class rather than the .cshtml, and use async methods for I/O so a slow database doesn't tie up request threads. For anything beyond trivial logic, put the query behind an injected service interface so pages stay thin and testable.
Connection strings belong in appsettings.json for development but should come from environment variables or a secrets store in production. The .NET Secret Manager (dotnet user-secrets) keeps development credentials out of source control, and the template's default configuration provider chain reads environment variables automatically.
Make it navigable and reasonably styled
A page that works alone still needs a shell. Layouts solve that once: Pages/Shared/_Layout.cshtml wraps every page, holds the navigation and footer, and includes the shared stylesheet references. Pages opt in through _ViewStart.cshtml, which sets Layout = "_Layout" for everything in the folder.
To add a page to navigation, open the layout and add a link beside the existing ones:
The asp-page tag helper builds the URL from the page path, so links survive route changes better than hard-coded strings. For MVC, asp-controller and asp-action do the same job.
Styling is plain CSS in wwwroot/css, loaded via the tag in the layout's . The template ships Bootstrap, which means you can compose most pages from its utility classes and components without writing much custom CSS. Override in a separate stylesheet loaded after the bundled one, so your rules win on specificity order without fighting the framework.
Static files in wwwroot are public by design. Never place configuration, source, or secrets there; anything an anonymous visitor can request is effectively published.
Two accessibility details are worth doing now rather than retrofitting: give every form input a real (the tag helpers do this when you use asp-for on a label), and keep heading levels sequential so screen readers can navigate the page outline.
Run, debug, and test before you deploy
Before deployment, you need confidence that the page behaves under failure, not just under the happy path. Development-time tooling makes this cheap.
Running with dotnet watch run rebuilds and restarts the app when files change, and the developer exception page shows detailed error information—stack traces, request details, and sometimes suggested fixes—for unhandled exceptions in development. That same page is dangerous in production, so the template only enables it in the Development environment; don't disable the environment check to "see errors" on a live site.
Logging is on by default through the built-in ILogger, with levels configured in appsettings.json. Inject a logger into a page model and record meaningful events—failed validation counts, external calls, slow queries—rather than logging everything indiscriminately.
For automated checks, the standard shape is an integration test that hosts the app in memory and issues HTTP requests. ASP.NET Core's WebApplicationFactory starts the real pipeline against a test server, so a test can request /Contact, post invalid data, and assert that the response contains the validation message. That catches the routing, binding, and validation wiring in one test without a browser. Unit tests cover page-model logic directly, and browser automation with Playwright or Selenium is worth adding only for flows with significant client-side behavior.
A failure pattern to watch for: your page works in development but returns 500 in production. The usual causes are a missing environment variable, a database migration not applied to the production database, or a file path assumption that doesn't hold where the app is deployed. Logs from the production environment will name which one; guessing wastes time.
Deploy with the right configuration and a real database
Deployment comes down to three concerns: how the app is hosted, how secrets reach it, and how the database schema stays current.
Publishing prepares the app for hosting:
That output folder is what you deploy. For most new ASP.NET Core apps, hosting options include:
App Service or a comparable managed platform. You deploy the publish output or a container; the platform handles the web server, TLS, and scaling. Containers. The SDK's built-in container support and the base images in Microsoft's registry produce a Linux image that runs in any container host or Kubernetes cluster. A plain server with a reverse proxy. Run the app as a service, put nginx or IIS in front for TLS and static-file caching, and forward requests.
Two settings matter in every option. First, set ASPNETCORE_ENVIRONMENT to Production on the host; the default when unset is Production, but an explicit setting prevents surprises. Second, supply the production connection string through environment variables or the platform's secret store, never a committed appsettings.json.
For schema changes, apply EF Core migrations as a deliberate deployment step, not on app startup in a way that races across multiple instances. Run dotnet ef database update as a release task with a connection string scoped to that job, or generate an idempotent SQL script (dotnet ef migrations script --idempotent) and review it before applying.
After deploying, verify with a checklist rather than a feeling: request the home page and your new page over HTTPS, submit the form end to end, confirm logs show the requests, and check that error pages show a friendly message rather than a stack trace. If form submissions fail while pages load, suspect antiforgery configuration behind the proxy or a missing forwarded-headers setup so the app knows the original scheme.
Failure modes and limits worth knowing before you build
The sequence above handles the common path. These are the edges that bite people, ordered roughly by how often they come up.
Environment and configuration drift. The single most common "worked locally" failure is configuration that lives only on a developer machine. Keep every required setting enumerated somewhere (a README table or a deployment manifest), and treat a missing setting as a deployment failure, not a runtime surprise.
Model validation gaps in APIs. On Razor Pages, validation runs automatically. If you add API endpoints that accept JSON, model validation still runs, but automatic 400 responses depend on configuration and controller attributes. Test invalid payloads explicitly; a happy-path test proves nothing about validation.
Async misuse. Blocking on async calls with .Result or .Wait() in request code can deadlock under load. Use async all the way through page handlers and data calls. Async void methods outside event handlers are a related trap.
Overusing client-side interactivity. Blazor and JavaScript each add a debugging surface. If a page is a form plus a list, server-rendered Razor Pages is simpler to test, faster to first paint, and easier to index. Add interactivity where a full reload genuinely hurts the experience.
Classic-versus-modern confusion. A tutorial referencing Global.asax, web.config transforms, or System.Web is for .NET Framework, and its code won't compile in ASP.NET Core. When a sample doesn't match, check its target framework before assuming you did something wrong.
Version-specific instructions. Template flags, default authentication setups, and framework APIs change between releases. When a command or property from any guide—including this one—doesn't match, the --help output from your installed SDK and the official docs for your version are authoritative. Treat a reference date as a starting point, not proof a command is current.
A realistic time estimate, clearly labeled as my rough planning figure rather than a measurement: a static informational page on the template takes an afternoon; a form-backed page with validation and a database table takes a few days including tests; a multi-page app with authentication, roles, and deployment pipelines is a multi-week effort. Scope creep in that last category is almost always structural (data model, auth, deployment) rather than visual.
Where you should stop and get help: if your organization handles regulated data, involves paid transactions, or runs ASP.NET Core behind an unfamiliar corporate proxy with authentication, the security and deployment details need someone who can see your environment. General guidance, including this article's, can't verify your TLS termination, secret handling, or data-protection key storage, and mistakes there are expensive.
FAQ
Do I need to know C# before starting ASP.NET Core? Yes, at a working level. You can copy a template and see a page, but every meaningful change—binding a model, writing a query, handling an error—is C#. Comfort with classes, async/await, and basic LINQ covers most page work.
Can I develop ASP.NET Core on a Mac or Linux machine? Yes. The SDK, runtime, command-line tools, and Visual Studio Code all run cross-platform, and the resulting app deploys the same way. Only the legacy .NET Framework path, including Web Forms, is Windows-only.
Which should I learn first, Razor Pages or MVC? Razor Pages. It teaches routing, model binding, validation, layouts, and dependency injection with less indirection, and those concepts transfer directly to MVC. Learn MVC when you hit an app structure that benefits from controllers, or when you join a codebase that uses it.
Is classic ASP.NET Web Forms still safe to build new projects on? Not for new work. It runs, but it's tied to .NET Framework, which Microsoft supports on a fixed lifecycle without new feature development, and it's Windows-only. Existing Web Forms apps can be maintained, but new pages belong on ASP.NET Core.