Web Development with .NET
Overview
Welcome to the official .NET web development tutorial series. This guide walks you through building modern, high‑performance web applications using ASP.NET Core, Razor Pages, Blazor, and MVC.
Getting Started
Install the .NET SDK and create your first web project.
dotnet new webapp -o MyFirstApp
cd MyFirstApp
dotnet run
Open https://localhost:5001
in your browser to see the default Razor Pages template.
Core Concepts
- Middleware: The request pipeline that processes HTTP requests.
- Routing: Mapping URLs to endpoints using attribute or conventional routing.
- Dependency Injection: Built‑in IoC container for managing services.
- Razor Pages vs MVC vs Blazor: Choose the right UI model for your project.
Sample Project: Todo List API
Below is a minimal API implementation for a Todo list.
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Hosting;
using System.Collections.Generic;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
var todos = new List<TodoItem>{
new TodoItem{Id=1, Title="Learn ASP.NET Core", IsDone=false},
new TodoItem{Id=2, Title="Build a project", IsDone=false}
};
app.MapGet("/todos", () => todos);
app.MapPost("/todos", (TodoItem todo) => { todos.Add(todo); return Results.Created($"/todos/{todo.Id}", todo); });
app.MapPut("/todos/{id}", (int id, TodoItem updated) =>
{
var todo = todos.Find(t => t.Id == id);
if (todo is null) return Results.NotFound();
todo.Title = updated.Title;
todo.IsDone = updated.IsDone;
return Results.NoContent();
});
app.MapDelete("/todos/{id}", (int id) =>
{
var todo = todos.Find(t => t.Id == id);
if (todo is null) return Results.NotFound();
todos.Remove(todo);
return Results.NoContent();
});
app.Run();
record TodoItem(int Id, string Title, bool IsDone);
Run the API with dotnet run
and explore it using Swagger UI (if Swagger is added).