Самое быстрое решение - добавить промежуточное ПО с app.UseDirectoryBrowser ();
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseDirectoryBrowser();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc();
}
Это дает следующий результат:
Кроме того, можно добавить путь запроса, чтобы он был включен в запрос.
app.UseDirectoryBrowser(requestPath:"/data");
т.е. : https://localhost:44386/data/
Последнее: могут быть предоставлены провайдер и форматер файла:
app.UseDirectoryBrowser(options:
new DirectoryBrowserOptions(
new SharedOptions()
{
// the IFileProvider class is a way to provide the files to be displayed
FileProvider = new MyFileProvider()
}
)
{
// The IFileFormatter implementation is a way to customize presentation of the directory
RequestPath = "/data2",
Formatter = new MyFileFormatter()
}
);