In ASP.NET MVC 5 I used
_myStem = new MyStemWrapper(Path.Combine(HttpRuntime.AppDomainAppPath, "mystem.exe"));
to get path to file.
In ASP.NET MVC 6 I can't get path by the same way. I need to get path before any requests since my wrapper is a singleton created by IOC
var d = AppDomain.CurrentDomain; // some path to C:\Users\username\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta5\bin
var r = HttpRuntime.BinDirectory; // ArgumentNullException
var r2 = HttpRuntime.AppDomainAppPath; // ArgumentNullException
var ap = Apllication.StartupPath; // Application class missing
var s = Server.MapPath("~/") // Server class missing
In ASP.NET 5 you can easily access these information using IApplicationEnvironment:
private readonly IApplicationEnvironment _app;
public HomeController(IApplicationEnvironment app)
{
_app = app;
}
public IActionResult Index()
{
var path = _app.ApplicationBasePath;
}
Update: If you want exactly the wwwroot path, You can inject IHostingEnvironment and get WebRootPath property:
private readonly IHostingEnvironment _app;
public HomeController(IHostingEnvironment app)
{
_app = app;
}
public IActionResult Index()
{
var path = _app.WebRootPath;
}
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