Reputation: 1125
What is the equivalent of HttpRuntime.AppDomainAppPath
in .NET Core? I moved a project from ASP.NET to core, and a few Libraries are not included (Such as System.Web
). Here is a small example:
sb.AppendLine("\"New Path\": \"" + newFile.FullName.Replace(HttpRuntime.AppDomainAppPath, "/");
Any help would be appreciated, thanks
Upvotes: 12
Views: 16233
Reputation: 21337
The IWebHostEnvironment
interface provides information about the environment including the base path (ContentRootPath). You can get an instance using dependency injection.
public class Startup
{
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// env.ContentRootPath;
}
}
EDIT: Previous version of this answer was using now obsolete IHostingEnvironment
. Consider using it with .net core
version 2.2
or earlier. Credit for pointing this out goes to @Jack Miller.
Upvotes: 10