-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Description
Description
When using .NET 9.0, according to the documentation:
Setting a default page provides visitors a starting point on a site. To serve a default file from wwwroot without requiring the request URL to include the file's name, call the UseDefaultFiles method.
However, it appears MapStaticAssets DOES NOT serve default documents. For example, if the web root is changed, i.e.:
web_app_options = new WebApplicationOptions()
{
WebRootPath = Path.Combine( content_root_path, @"www" );
};
web_app_builder = WebApplication.CreateBuilder( web_app_options );
and middleware is configured as per the documentation (that is, use MapStaticAssets instead of UseStaticFiles), i.e.:
default_file_opts = new();
default_file_opts.DefaultFileNames.Clear();
default_file_opts.DefaultFileNames.Add( "index.html" );
app.UseDefaultFiles( default_file_opts );
app.MapStaticAssets();
When the app is run, a request to "/" should serve the "index.html" file, but instead the server responds with a 404 error!
However, by adding a call to UseStaticFiles(), the app works as expected, i.e.:
default_file_opts = new();
default_file_opts.DefaultFileNames.Clear();
default_file_opts.DefaultFileNames.Add( "index.html" );
app.UseDefaultFiles( default_file_opts );
app.UseStaticFiles();
app.MapStaticAssets();
The code above works, but what is the point of MapStaticAssets then? Given that UseStaticFiles is terminal, does MapStaticAssets do anything?
The documentation needs to include:
-
Clarity on how to serve default documents when using MapStaticAssets WITHOUT using UseStaticFiles (if possible?)
-
Documentation for the manifest file used by MapStaticAssets (couldn't seem to find any).
Thank-you in advance.
Page URL
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/fundamentals/static-files.md
Document ID
3fec6e08-fc99-7a5c-796f-3f2347cad891
Platform Id
5c42c2c8-be1b-60de-8cde-f9b8d8c24f5f
Article author
Metadata
- ID: d47f38e2-bc36-cfb8-b0cc-17a534689f8b
- PlatformId: 5c42c2c8-be1b-60de-8cde-f9b8d8c24f5f
- Service: aspnet-core
- Sub-service: fundamentals