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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With