What happens when you open a web page

From typing a URL to seeing the page: DNS, TCP, TLS, the HTTP request, the app and the database.

Time O(1)Space O(1)Code C#
Watch it animatedStep through it, with the running line highlighted. Free with an account.

The idea

A page load is a chain: the browser resolves the name with DNS, opens a TCP connection, secures it with TLS, sends an HTTP request with method, path, headers and cookies, and the server routes it to code that may query a database before sending back a status code, headers and a body.

Code

// Server side of one request in ASP.NET Core
app.MapGet("/api/profile", async (HttpContext ctx, AppDb db) =>
{
    var user = ctx.User.Identity?.Name;
    if (user is null) return Results.Unauthorized();
    var profile = await db.Profiles.FindAsync(user);
    return Results.Ok(profile);
});
// Browser:  GET /api/profile HTTP/1.1
//           Host: example.com  Cookie: session=...

Tips

In the .NET library

Kestrel receives the request, middleware runs in order (HTTPS redirection, authentication, authorization), then the endpoint runs.