I just spent the last couple of hours on the same issue. I'm not sure that the result will be the same, since you seem to be running one of two applications.
I set ASPNETCORE_ENVIRONMENT to "Staging" as a system variable through "Advanced System Settings" in Windows Server 2008 R2 and always ended up in the "Production" environment (which is the default environment if it cannot find the setting anywhere).
Using "set" from the command line showed the expected results "ASPNETCORE_ENVIRONMENT = Staging".
A call to Environment.GetEnvironmentVariable ("ASPNETCORE_ENVIRONMENT") returns null. I created another variable called "Test", which also returned zero. A call to any other existing variable returned the expected results.
I tried reusing the application pool by changing the application pool user, restarting IIS through the management console, even restarting the World Wide Web publishing service (possibly the same as reset in the IIS mgmt IIS console), all to no avail.
Rebooting the server was the only way to force the application to return the expected result.
source share