public static IApplicationEnvironment GetApplication(this RazorPage page)
{
var ae = page.Context.RequestServices.GetService(typeof(IApplicationEnvironment)) as IApplicationEnvironment;
//ae.ApplicationBasePath
return ae;
}
or
private readonly IApplicationEnvironment _appEnvironment;
public HomeController(IApplicationEnvironment appEnvironment)
{
_appEnvironment = appEnvironment;
}
public IActionResult Index()
{
var rootPath = _appEnvironment.ApplicationBasePath;
return View();
}