Serving default documents

The frontend of modern web applications consists mostly of static files. Therefore, pointing the server to the client directory and instructing it to serve its entire content as static files is a common practice. In such situations, you will also want to send the user the main application file, such as index.html, when they navigate to the static folder. These files are called default documents.

Defining default documents for a static folder is done via the UseDefaultFiles method. Within the Startup.cs file, locate the Configure method and add the following marked line:

app.UseDefaultFiles();app.UseStaticFiles(); 
UseDefaultFiles must be used before the UseStaticFiles call. If they are called in the opposite order, ...

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.