我可以將任意目錄映射為 wwwroot 的子目錄嗎?也就是說,該目錄不在檔案系統中的 wwwroot 下,但在我的應用程式中,它是這樣處理的。
例如,我創建了一個 ASP.NET 6.0 Blzor Server 專案。程式 dll 路徑在/app/proj1/BlazorApp1.dll. 如果有圖片/app/proj1/wwwroot/images/dog.jpg,可以<img src="images/dog.jpg"/>在我的頁面中使用。但是如果我不想讓這個images目錄實際上在wwwroot檔案系統的目錄下呢?目錄可以在其他地方嗎/data/images,我將該路徑映射到wwwroot/images,以便/data/images/dog.jpg可以<img src="images/dog.jpg"/>在我的應用程式中呈現?
uj5u.com熱心網友回復:
我知道有 3 種方法可以做到這一點,首先調整設定,這在 msdn 上明確記錄在“在 web 根目錄之外提供檔案”標題下;
app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider( Path.Combine(builder.Environment.ContentRootPath, "MyStaticFiles")), RequestPath = "/StaticFiles" });

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/523670.html
