liveBook · Manning

UseStaticFiles

As explained in ASP.NET Core in Action, 3e

UseStaticFiles is an ASP.NET Core application-builder method that adds static-file serving middleware to the request pipeline.

UseStaticFiles adds static-file middleware to an ASP.NET Core request pipeline. The middleware checks the wwwroot folder and returns a requested file when it exists. section 4.2.2

Minimal static-file pipeline

Create the application, build it, add static-file middleware, and run it: WebApplicationBuilder builder = WebApplication.CreateBuilder(args); WebApplication app = builder.Build(); app.UseStaticFiles(); app.Run(); A request for /moon.jpg is served from wwwroot/moon.jpg. A request for a missing file passes through and produces a 404 response. No services are required for this pipeline. section 4.2.2

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains registration, wwwroot lookup, successful responses, pass-through behavior, and automatic 404 handling.
Examples
Uses Program.cs, wwwroot/moon.jpg, missing.jpg, and browser responses to demonstrate serving and failure cases.
What it assumes
Requires an ASP.NET Core application with a wwwroot folder and needs no additional services.
What you can do after
Operate/configure an ASP.NET Core pipeline that serves existing files and returns 404 responses for missing files.
How it connects
Connects static-file middleware with middleware pipelines, wwwroot, request handling, and HTTP 404 responses.

Also explained in

Compare how 2 books explain UseStaticFiles →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.