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。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM