ASP.NET Core访问wwwroot下的文件

例如,访问wwwroot下的files/file.pdf

复制代码
    public class SendEmailController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        private IWebHostEnvironment _hostEnvironment;
        public SendEmailController(IWebHostEnvironment hostEnvironment)
        {
            _hostEnvironment = hostEnvironment;
        }

        [HttpPost]
        public IActionResult Index(EmailModel model)
        {
            // get the file path
            string fileName = Path.Combine(_hostEnvironment.WebRootPath, "files", "file.pdf");

            // code omitted
return View(); } }
复制代码

IHostingEnvironment在未来的版本中将不再支持,所以建议使用IWebHostEnvironment。

posted @   Kyle0418  阅读(4074)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示