Determine ASP.NET Core environment name in the views
You can inject the service IHostingEnvironment
in your view by doing@inject Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnv
and do a @hostingEnv.EnvironmentName
I just made a simple API controller:
[Route("api/[controller]")]
public class DebugController : Controller
{
private IHostingEnvironment _hostingEnv;
public DebugController(IHostingEnvironment hostingEnv)
{
_hostingEnv = hostingEnv;
}
[HttpGet("environment")]
public IActionResult Environment()
{
return Ok(_hostingEnv.EnvironmentName);
}
Then I just run /api/debug/environment
to see the value.