ASP.net core 中控制器直接访问wwwroot的静态文件

ASP.net core 中控制器直接访问wwwroot的静态文件

 

示例代码:

using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace ProductQRcode.Controllers
{
public class HomeController : Controller
{
private IWebHostEnvironment _webHostEvironment;
public HomeController(IWebHostEnvironment webHostEvironment)
{
_webHostEvironment = webHostEvironment;
}
public IActionResult Index()
{
var filePath = Path.Combine(_webHostEvironment.WebRootPath, "index.html");
return PhysicalFile(filePath, "text/html");
}
}
}

 

上一篇:Firefox 扩展插件


下一篇:学习Linux的第13天