In ASP.NET Core we can have different hosting environments, this is supported by an environment variable called ASPNETCORE_ENVIRONMENT. You can see this value is already set to Development:
This value is active as long as you run your application inside Visual Studio, So when you deploy your application you must change this value. Actually, this value comes from a file called launchSettings.json:
You can determine what the environment is by using IHostingEnvironment:
This object also has a method called IsEnvironment for using custom environment:
One interesting thing is that the Startup class itself supports different environments, it means that for each environment you can have both Configure and ConfigureServices:
Now you might ask how we can set this environment variable, well there are several ways that you can use, this great post explains them in details.