因此,从环境中读取的键值会替代从 appsettings.json、appsettings.Environment.json 和机密管理器中读取的值 。

 

public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration((hostingContext, config) =>
            {
                config.AddEnvironmentVariables(prefix: "MyCustomPrefix_");
            })
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
}

在上述代码中:

  • JSON 配置提供程序。
  • 这包括没有前缀的环境变量。

前缀会在读取配置键值对时被去除。

 

 

.NET 通用主机。

 

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iis": {
      "applicationUrl": "http://localhost/CoreDemon",
      "sslPort": 0
    },
    "iisExpress": {
      "applicationUrl": "http://localhost:54936",
      "sslPort": 44323
    }
  },
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "CoreDemon": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_Name": "吴德群",
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    }
  }
}
launchSettings.json

相关文章:

  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
猜你喜欢
  • 2021-11-16
  • 2022-12-23
  • 2022-02-23
  • 2021-08-09
  • 2021-12-05
  • 2021-11-19
  • 2021-06-01
相关资源
相似解决方案