首页 > Web开发 > 详细

ASP.NET Core 添加静态目录访问、使其它目录可被访问

时间:2019-03-10 10:23:31      阅读:190      评论:0      收藏:0      [点我收藏+]
原文:ASP.NET Core 添加静态目录访问、使其它目录可被访问

使用app.UseFileServer

在 public void Configure(){}中,修改或添加

1 app.UseFileServer(new FileServerOptions()
2             {
3                 FileProvider =new PhysicalFileProvider
4                 (
5                     Path.Combine(Directory.GetCurrentDirectory(),@"StaticFile/Image")),   //实际目录地址
6 RequestPath=new Microsoft.AspNetCore.Http.PathString("/Image"), //用户访问地址
7 EnableDirectoryBrowsing=true //开启目录浏览 9 });

EnableDirectoryBrowsing=true  表示是否开启目录浏览,当为true时,访问该目录,会列出文件列表,如图

技术分享图片

 

这样用户访问http://url/Image时,实际访问的是 StaticFile/Image。

app.UseFileServer包含了
app.UseStaticFiles //静态文件访问
app.UseDefaultFiles //默认文件设置
app.UseDirectoryBrowsing //开启目录浏览

亦可使用 app.UseStaticFiles,在public void Configure(){}中修改或添加

1  app.UseStaticFiles(new StaticFileOptions()
2             {
3                  FileProvider = new PhysicalFileProvider
4                 (
5 Path.Combine(Directory.GetCurrentDirectory(),@"StaticFile/Image")), //实际目录地址
6 RequestPath=new Microsoft.AspNetCore.Http.PathString("/Image"), //用户访问地址
7 });

 

ASP.NET Core 添加静态目录访问、使其它目录可被访问

原文:https://www.cnblogs.com/lonelyxmas/p/10504222.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!