azure - Azure AppService 上加载了错误的设置
问题描述
我有一个具有身份服务器设置的 asp.net 核心应用程序。为此,我有一个 appsettings.json、一个 appsettings.Development.json 和一个 appsettings.Production.json。
appsettings.json:
..
"ApplicationInsights": {
"InstrumentationKey": ""
},
"IdentityServer": {
"Clients": {
"ApplySupportTool.Client": {
"Profile": "IdentityServerSPA"
}
}
},
"BuildInfo": {
"Environment": "Integration",
"Version": "1.0.0 Beta"
},
..
appsettings.Development.json
{
"IdentityServer": {
"Key": {
"Type": "Development"
}
}
}
appsettings.Production.json
{
"IdentityServer": {
"Key": {
"Type": "Store",
"StoreName": "My",
"StoreLocation": "CurrentUser",
"Name": "[Name]"
}
}
}
在本地工作没有问题,我可以通过从启动设置中删除环境变量在它们之间切换:
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
在加载类似于默认模板的设置文件方面,我的 HostBuilder 是这样创建的,没有对设置文件进行特殊添加。
public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(webHostBuilder =>
{
webHostBuilder
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseAzureAppServices();
})
.UseSerilog();
}
当我签入 Startup.cs 的构造函数时,我可以验证它是否也加载了附加文件。
但是当我将它部署到 Azure 时,似乎总是会加载开发版本。据我所知,没有设置任何值,它应该用于生产(在本地工作)。可以肯定的是,我还尝试将值为“Production”的 ASPNETCORE_ENVIRONMENT 显式添加到我的 AppService 中。但这也没有改变任何东西。我必须以特殊方式加载它吗?
解决方案
希望 Development 不会在 Program.cs 中保持最后,它会覆盖您的 appsetting 和 production.json
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
同样在 WebAPP 刀片中,如果您要覆盖 ASPNETCORE_ENVIRONMENT 变量,则需要重新启动实例以反映并重新加载更改。
此外,有关您的 program.cs 的更多信息将有助于我们找到根本原因。
推荐阅读
- git - 获取跟踪文件的 git repo 路径的最有效方法
- jquery - jQuery 显示/隐藏用于单个页面中的多个不相关的单选按钮集
- java - 有没有办法从 HTML 中清除无效属性?
- image - 如何无限制地从 Cloudinary API 获取所有图像或如何使用 next_cursor?
- javascript - React.js + axios:如何避免在我的数据表上硬编码数据?
- java - Java XMLDecoder 将文件读入 arraylist 和 ArrayIndexOutOfBoundsException
- amazon-web-services - python aws sdk 缺少转录流 API
- javascript - 为 CSS 和 Bootstrap 4 使用 shadow dom 构建自定义元素
- powershell - 如何使用 powershell 将一些日志文件内容转换为表格格式
- html - 将较大的字符串作为较小的字符串(放大或缩小)[CSS]