如果您想访问位于wwwroot
文件夹之外的文件,您需要按照以下方式配置Static File Middleware:
app.UseStaticFiles();// For the wwwroot folder
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "Uplodaed_Documents")),
RequestPath = "/Uplodaed_Documents"
});
//Enable directory browsing
app.UseDirectoryBrowser(new DirectoryBrowserOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "Uplodaed_Documents")),
RequestPath = "/Uplodaed_Documents"
});
app.UseMvc();
您可以参考 asp.net core 静态文件 Serve files outside of web root