【发布时间】:2020-05-14 15:43:13
【问题描述】:
我们公司已经偏离了微软标准环境设置。
我们有以下环境
- 本地 - 针对 docker compose 文件进行本地开发的环境,基础设施作为容器运行
- 开发 - 用于 3rd 方团队的集成环境,我们将 API 连接到他们正在处理的前端。相当不稳定,因为集成环境应该是
- 暂存 - 为我们的利益相关者提供更稳定的审核环境
我们的Startup.cs 类看起来像这样
public void ConfigureLocalServices(IServiceCollection services)
{
services
.AddApplicationServices(Configuration)
.AddLocalIntegrationEvents(Configuration)
.AddLocalLogging(Configuration);
}
public void ConfigureDevelopmentServices(IServiceCollection services)
{
services
.AddApplicationServices(Configuration)
.AddDevelopmentLogging(Configuration)
.AddDevelopmentIntegrationEvents(Configuration);
}
如您所见,它既美观又整洁,我们根据环境配置我们的应用程序。
现在讨论我们的问题 - 由于默认 Web 构建器仅在环境为开发时添加用户机密(据我所知,如果您在本地工作,您应该使用默认环境)我们遇到运行时异常问题没有加载红隼 HTTPS 证书,因为这个秘密是
现在缺少"Kestrel:Certificates:Development:Password": "100e0e22-09ea-40e4-bef9-469289bf8786"。
我已经暂时解决了这个问题
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
//Load in secrets if environment is local as well to get our HTTPS certs loaded correctly
if (hostingContext.HostingEnvironment.EnvironmentName.Equals("Local", StringComparison.InvariantCultureIgnoreCase))
config.AddUserSecrets<Startup>();
})
.UseStartup<Startup>()
.UseSerilog();
一些开发人员设置了特定于另一个环境的秘密,这会在运行时导致更多问题。
据我了解,秘密文件不是特定于环境的,因此我们无法添加“本地秘密”。
为我们解决此问题的最佳方法是什么?我们的方法完全不正确吗?
【问题讨论】:
标签: c# asp.net-core .net-core