若访问项目文件wwwroot以外的其他静态文件使用如下方式访问
1.配置文件中配置路径(appsetting)
"App": { "ServerRootAddress": "https://localhost:44301/", "ClientRootAddress": "https://localhost:4200/", "CorsOrigins": "http://localhost:4200,http://localhost:9876,http://localhost:4201,http://localhost:4202", "SwaggerEndPoint": "/swagger/v1/swagger.json", "AllowAnonymousSignalRConnection": "true", "FileRoot": "E:\\Imgs" },
2.StartUp中配置app.UseStaticFiles
1 app.UseStaticFiles(); 2 if (!Directory.Exists(_appConfiguration["App:FileRoot"])) 3 { 4 Directory.CreateDirectory(_appConfiguration["App:FileRoot"]); 5 } 6 app.UseStaticFiles(new StaticFileOptions() 7 { 8 FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), _appConfiguration["App:FileRoot"])), 9 RequestPath = new PathString("/virtualFile") 10 });
3.使用
如访问E盘下Imgs中的图片
路径可写成如下即可访问
https://localhost:44301/virtualFile/pic.jpg
没有回复内容