A static file is content served without generating a fresh response for each request. Images, CSS stylesheets, JavaScript files, and HTML pages can all serve this role. Unlike a shopping cart or product detail generated from a user’s actions, the file’s contents do not depend on the request. In an ASP.NET Core project, the conventional home for these files is wwwroot. section 15.4
Put the file in wwwroot, then make sure the application can serve it. A minimal Program.cs can call app.UseStaticFiles() before app.Run(). This adds static-file handling to the HTTP request pipeline; simply creating a file is not the whole setup in that example. Some project templates already configure static-content support, so check the application rather than assuming every project starts alike. section 4.3 section 3.2.9
Listing 4.4 Adding a statement in the Program.cs file in the MyProject folder
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.UseStaticFiles();
app.Run();
The Program.cs listing shows where UseStaticFiles() is added in a minimal application. section 4.3
Check the URL, not just the folder
With static-file support enabled, a demo.html file in wwwroot can be checked at http://localhost:5000/demo.html after running the application. The URL does not include wwwroot. Likewise, a stylesheet at wwwroot/css/styles.css is linked as /css/styles.css. section 4.3 section 3.2.9
Static files also support pages whose main response is handled elsewhere. A form view can link to a CSS file that highlights validation errors. For an unhandled exception, UseExceptionHandler("/error.html") can direct the browser to an HTML file in wwwroot—provided static-file middleware is also in the pipeline. Keep that error page simple; an elaborate error handler can fail while handling the original failure. section 3.2.9 section 16.6.1





