└── aspnetcore-path
└── src
└── AspNetCorePath.Web
├── Controllers
├── Models
├── Properties
├── Views
├── bin
├── obj
├── wwwroot
├── Program.cs
├── Startup.cs
├── appsettings.Development.json
├── appsettings.json
└── AspNetCorePath.Web.csproj
Let's create a .NET Core web application and we retrieve the content root and wwwroot path.
In many ways we can get this result.
- Constructor Injection in Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HomeController : Controller | |
{ | |
private readonly IHostingEnvironment _hostingEnv = null; | |
string AppBasePath = null; | |
string ContentRootPath = null; | |
public HomeController(IHostingEnvironment HostingEnv) | |
{ | |
_hostingEnv = HostingEnv; | |
AppBasePath = _hostingEnv.WebRootPath; //path to wwwroot | |
ContentRootPath = _hostingEnv.ContentRootPath; //path to GetBasePath | |
} | |
public IActionResult Index() | |
{ | |
return View(); | |
} | |
} |
- Constructor Injection in Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Startup(IConfiguration configuration,IHostingEnvironment _env) | |
{ | |
Configuration = configuration; | |
string sAppPath = _env.ContentRootPath; //Application Base Path | |
string swwwRootPath = _env.WebRootPath; //wwwroot folder path | |
} |
Summary