Can I map an arbitrary directory as a subdirectory of wwwroot? That is, the directory is not under wwwroot in the file system, but within my app, it is treated like so.
For example, I have created an ASP.NET 6.0 Blzor Server project. The programme dll path is in /app/proj1/BlazorApp1.dll
. If there is an image at /app/proj1/wwwroot/images/dog.jpg
, it can be rendered using <img src="images/dog.jpg"/>
in my page. But what if I do not want to have this images
directory actually under the wwwroot
directory on the file system? Can the directory be somewhere else like /data/images
, and I map that path to wwwroot/images
, so that /data/images/dog.jpg
can be rendered with <img src="images/dog.jpg"/>
within my app?
CodePudding user response:
There are 3 ways to do this that i know of, Firstly adjusting the settings, which is clearly documented on msdn, under the 'Serve files outside of web root' header;
app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider( Path.Combine(builder.Environment.ContentRootPath, "MyStaticFiles")), RequestPath = "/StaticFiles" });