Create a new project
Open a terminal in your projects directory and enter:
dotnet new web -n PicnicHello
cd PicnicHelloThe web template creates a small ASP.NET Core application.
Run it
dotnet runFind 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
- What command creates the project?
- Which file contains our endpoint?
- Why do we open the address shown in the terminal rather than assume port 5000?