I am building a Web API using dotnet core 3.1 and now I got into the need to store a kind of sensitive information on a Windows Environment variable which I already did. Let's call it MY_WIN_VAL_X.
I tried to use the following code on the ConfigureServices method on the Startup.cs (link)
public class Startup
{
private IHostEnvironment Environment { get; set; }
public Startup(IConfiguration configuration, IHostEnvironment environment)
{
Environment = environment;
this.Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
...other code
var myEnvValX = Environment.GetEnvironmentVariable("MY_WIN_VAL_X");
}
}
However, I got this error:
'IHostEnvironment' does not contain a definition for 'GetEnvironmentVariable' and no accessible extension method 'GetEnvironmentVariable' accepting a first argument of type 'IHostEnvironment' could be found (are you missing a using directive or an assembly reference?) [API]csharp(CS1061)
Does anyone knows how to achieve it? How to get the custom Windows environment variable?