//app.UseStaticFiles(); // 啟動靜態檔案中介軟體,預設訪問wwwroot app.UseStaticFiles(new StaticFileOptions() { //修改預設訪問地址為MyStaticFiles檔案 FileProvider = new PhysicalFileProvider(Path.Combine(builder.Environment.ContentRootPath,"MyStaticFiles")), //設定訪問字首,預設是http:xxxxxxx:8080/1.png,新增預設字首之後 http:xxxxxx:8080/StaticFiles/1.png RequestPath = "/StaticFiles" });
全部程式碼: