【发布时间】:2015-08-25 07:50:32
【问题描述】:
很抱歉提出一个菜鸟问题,但我似乎无法从 Controller 获取 Server.MapPath。我需要从 wwwroot 的图像文件夹中输出 json 文件列表。它们位于 wwwroot/images。如何获得可靠的 wwwroot 路径?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using www.Classes;
using System.Web;
namespace www.Controllers
{
[Route("api/[controller]")]
public class ProductsController : Controller
{
[HttpGet]
public IEnumerable<string> Get()
{
FolderScanner scanner = new FolderScanner(Server.MapPath("/"));
return scanner.scan();
}
}
}
Server.MapPath 似乎在 System.Web 命名空间中不可用。
项目正在使用 ASP.NET 5 和 dotNET 4.6 框架
【问题讨论】:
-
请更新您正在使用的 .Net 框架的版本。
标签: c# asp.net rest asp.net-core asp.net-core-mvc