I see you are dealing with
MVC6
(as it shown in the question tag).
Server.MapPath
may not work. You need to deal with
IApplicationEnvironment
interface, namespace
Microsoft.Extensions.PlatformAbstractions
to get the server path. Something like
private readonly IApplicationEnvironment _appEnvironment;
public HomeController(IApplicationEnvironment appEnvironment)
{
_appEnvironment = appEnvironment;
}
public IActionResult Index()
{
var rootPath = _appEnvironment.ApplicationBasePath;
return View();
}
For more look here.
Environment Variables in ASP.NET Core Apps[
^]