简体   繁体   中英

Is it possible to serve static files from outside the wwwroot folder?

I have an ASP.NET MVC 6 project with the following structure:

project/
  wwwroot/
  custom/
  project.json

I want to serve files from custom as it if was a virtual folder into http://localhost/custom without having to copy them during development.

Is it possible to do this in vNext without a virtual folder from IIS (say, using the StaticFile middleware)?

You can set the file provider on the options object when using the middleware.

app.UseStaticFiles(new StaticFileOptions() {
    FileProvider = new PhysicalFileProvider(@"C:\Path\To\Files"),
    RequestPath = new PathString("/somepath")
})

See: https://github.com/aspnet/StaticFiles/blob/master/src/Microsoft.AspNetCore.StaticFiles/Infrastructure/SharedOptions.cs#L44

and

https://github.com/aspnet/FileSystem/blob/dev/src/Microsoft.Extensions.FileProviders.Physical/PhysicalFileProvider.cs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM