Setting the server to serve static files

ASP.NET Core, by default, doesn't serve static files to end users. Even though the content root and web root paths have default values, you have to explicitly indicate that static files should be served. To do so, open the Startup.cs file, locate the Configure method, and add the following line:

app.UseStaticFiles();

Once this is placed in the right location, the ASP.NET Core platform will serve static files from the web root folder.

Make sure that the web root folder itself is not part of the URL. The following table demonstrates the physical file location and the matching URL, assuming that the default web root path, wwwroot, hasn't been changed:

Physical file location

URL

wwwroot/images/logo.png ...

Get Hands-On Full-Stack Web Development with ASP.NET Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.