【发布时间】:2019-06-11 05:59:37
【问题描述】:
我正在使用带有 MVC 的 asp net core 2.0.5,并希望在wwwroot 之外提供一个静态文件夹。
我的输入文件如下所示。
wwwroot
staticfolder
10
index.html
image1.png
image2.png
sub-folder
image3.jpg
index.html 是由其他程序生成的。所有图像都在 index.html 中使用。
我们希望在检查身份验证后进入服务器,即用户可以通过路径api/flight/10/index.html查看index.html。但我需要检查访问资源flight 10 的用户权限。
我了解Physicalfile 可用于在 wwwroot 之外提供静态文件(例如 *.png),还可以将 app.UseStaticFiles 配置为在 startup.cs 中提供文件夹和文件。
一些伪代码作为最小示例。
[Route("api/flight/{flight}/index.html")]
[HttpGet]
public IActionResult GetImageThumbnail(
[FromRoute] int flight)
{
// Check permission
List<Flight> data = _context
.Flight(id: flight)
.ToList();
if (data.Count() == 0)
{
return NotFound("No permission.");
}
// data[0].BaseFolder is a folder outside wwwroot
string filename = data[0].BaseFolder + "/index.html";
// Return the content for index.html
...
}
所以我的问题是我应该如何使用上面类似的方法来服务一个混合了 html 和图像的文件夹。
【问题讨论】:
-
您是否希望对
wwwroot中的特定文件夹进行飞行检查? -
不,在 wwwroot 文件夹之外
-
您能否阐明期望的最终结果应该是什么样子?输入是什么,输出是什么。
-
谢谢。我会尽力澄清我的问题。
标签: c# asp.net asp.net-mvc asp.net-core