Reputation: 1561
Here I have a static HTML file (index.html) placed in a folder named Test
inside wwwroot
.
How can I configure the app to make it accessible at /Test
address?
Currently seems I need to specify the whole address: "test/index.html"
Upvotes: 4
Views: 2057
Reputation: 4919
To automatically look for the following files, when you route to a directory in wwwroot
:
Just before UseStaticFiles()
in the Configure
method in Startup.cs, add a call to UseDefaultFiles()
:
app.UseDefaultFiles();
app.UseStaticFiles();
If you want file names other than the four mentioned above, you can create an instance of DefaultFilesOptions
and add the file names you want:
var options = new DefaultFilesOptions();
options.DefaultFileNames.Clear();
options.DefaultFileNames.Add("mycustomfilename.html");
app.UseDefaultFiles(options);
app.UseStaticFiles();
For more info, see serving default documents.
Also, if you want to allow directory browsing, you can replace both the above calls with:
app.UseFileServer(enableDirectoryBrowsing: true);
The above combines UseDefaultFiles()
, UseStaticFiles()
and UseDirectoryBrowser()
.
Upvotes: 5