【发布时间】:2020-04-24 04:42:05
【问题描述】:
我正在使用 dotnet core 3.1 构建一个 Web API,现在我需要在 Windows 环境变量中存储一种敏感信息,我已经这样做了。我们称它为 MY_WIN_VAL_X。
我尝试在 Startup.cs (link) 上的 ConfigureServices 方法上使用以下代码
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");
}
}
但是,我收到了这个错误:
“IHostEnvironment”不包含定义 'GetEnvironmentVariable' 并且没有可访问的扩展方法 'GetEnvironmentVariable' 接受类型的第一个参数 可以找到“IHostEnvironment”(您是否缺少 using 指令 还是程序集参考?)[API]csharp(CS1061)
有谁知道如何实现它?如何获取自定义的 Windows 环境变量?
【问题讨论】:
标签: asp.net-core .net-core asp.net-core-mvc asp.net-core-2.0 asp.net-core-webapi