All you need is a variable of type IHostingEnvironment
:
get environment name:
env.EnvironmentName
for predefined Development
, Staging
, Production
environments the best way is to use extension methods from HostingEnvironmentExtensions class
env.IsDevelopment()
env.IsStaging()
env.IsProduction()
correctly ignore case (another extension method from HostingEnvironmentExtensions:
env.IsEnvironment("environmentname")
case sensitive variant:
env.EnvironmentName == "Development"