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)?
ASP.NET Core application cannot serve static files by default. We must include Microsoft. AspNetCore. StaticFiles middleware in the request pipeline.
To serve static files for Go 1.12+ in the standard environment, you define the handlers in your app. yaml file using either the static_dir or static_files elements. The content in the static files or static directories are unaffected by the scaling settings in your app.
To serve static files from an ASP.NET Core app, you must configure static files middleware. With static files middleware configured, an ASP.NET Core app will serve all files located in a certain folder (typically /wwwroot).
The wwwroot folder is new in ASP.NET 5 to store all of the static files in your project. Any files including HTML files, CSS files, image files, and JavaScript files which are sent to the user's browser should be stored inside this folder.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With