ASP.NET Core · Module 1 · Lesson 02 / 04

Make your first working website

Create an ASP.NET Core project and run it locally.

Create a new project

Open a terminal in your projects directory and enter:

dotnet new web -n PicnicHello
cd PicnicHello

The web template creates a small ASP.NET Core application.

Run it

dotnet run

Find the Now listening on: address in the terminal, then open that exact address in your browser. The port depends on your machine and launch settings. Stop the server with Ctrl+C.

Read Program.cs

A minimal application may resemble:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.Run();

MapGet describes what happens when someone requests the home URL. Run() starts serving requests.

Try a small change

Replace Hello World! with your own greeting, save, stop the server and run it again. Refresh the browser and observe the change.

Checkpoint

  1. What command creates the project?
  2. Which file contains our endpoint?
  3. Why do we open the address shown in the terminal rather than assume port 5000?