Test page foo.html
The use of middleware in Startup.cs
code show as below:
1 DefaultFilesOptions defaultFilesOptions = new DefaultFilesOptions(); 2 defaultFilesOptions.DefaultFileNames.Clear(); 3 defaultFilesOptions.DefaultFileNames.Add("foo.html"); 4 app.UseDefaultFiles(defaultFilesOptions); 5 app.UseStaticFiles();
or:
1 FileServerOptions fileServerOptions = new FileServerOptions(); 2 fileServerOptions.DefaultFilesOptions.DefaultFileNames.Clear(); 3 fileServerOptions.DefaultFilesOptions.DefaultFileNames.Add("foo.html"); 4 app.UseFileServer(fileServerOptions);
operation result:
Static Files in ASP.NET Core
AN ASP.NET Core the Application default By by Will not serve static Files ; static files are not supported when // the default ASP.NET Core application case.
Files for static default Directory at The IS wwwroot wwwroot when // providing default path for storing static files;;
Files static serve the To UseStaticFiles () Middleware IS required; // UseStaticFiles (). You must use a static file
A default File serve the To UseDefaultFiles () Middleware IS required; // UserDefaultFiles (). We must use the default file
The following are the default files: // lists four default filename
index.htm
index.html
default.htm
default.html
UseDefaultFiles () the MUST BE Registered the before UseStaticFiles (); // UseDefaultFiles () must precede UseStatciFiles () to register.
UseFileServer COMBINES at The functions on this page of UseStaticFiles, UseDefaultFiles and UseDirectoryBrowser Middleware. // UseFileServer collection UseStaticFiles, all these functions UseDefaultFiles and UseDirectoryBrowser middleware.
Transfer tubing> Static Files in ASP NET Core