在用于容器的 Azure Web App 上使用 ASP.Net Core 配置 AppSettings:冒号在哪里? [英] Configuring AppSettings with ASP.Net Core on Azure Web App for Containers: Whither Colons?

查看:15
本文介绍了在用于容器的 Azure Web App 上使用 ASP.Net Core 配置 AppSettings:冒号在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一下这个 appsettings.json:

<代码>{父母":{"ChildOne": "来自 secrets.json 的 C1",ChildTwo":来自 secrets.json 的 C2"}}

根据微软 (

但是,如果您使用 Web App for Containers/即部署到 Linux 上的 Azure 应用服务的 Docker 映像(

为什么?

当您将鼠标悬停在错误上时,您会看到以下消息:此字段只能包含字母、数字 (0-9)、句点 (".") 和下划线 ("_").唉,使用 . 不起作用.

如何在 Azure 中配置say Parent:ChildOne?Parent.ChildOne 不起作用.任何人都可以建议吗?我找不到这方面的任何文档....

解决方案

经过比我想承认的更多的实验,我想我有答案了.

在应用服务上使用 : 时,在具有容器的应用服务上使用 __(双下划线).

所以 Parent__ChildOne 而不是 Parent:ChildOne.

为了阅读更多内容(不多),我在这里写了一篇博文:https://blog.johnnyreilly.com/2018/07/28/azure-app-service-web-app-containers-asp-net-nested-configuration/

Consider this appsettings.json:

{
  "Parent": {
    "ChildOne": "C1 from secrets.json",
    "ChildTwo": "C2 from secrets.json"
  }
}

According to Microsoft (https://blogs.msdn.microsoft.com/waws/2018/06/12/asp-net-core-settings-for-azure-app-service/), if an app using this config was deployed to an AppService in Azure, the config could be overwritten by creating Application settings in Azure in the style Parent:ChildOne / Parent:ChildTwo. To be clear: using colons to target a specific piece of config.

This works just fine with a standard AppService:

However, if you're using Web App for Containers / i.e. a Docker image deployed to an Azure App Service on Linux (https://docs.microsoft.com/en-us/azure/app-service/containers/app-service-linux-intro) you cannot use colons:

Why?

When you hover over the error you see this message: This field can only contain letters, numbers (0-9), periods ("."), and underscores ("_"). Using . does not work alas.

How do you configure say Parent:ChildOne in Azure? Parent.ChildOne does not work. Can anyone advise? I can't find any docs on this....

解决方案

After more experimentation than I'd like to admit I think I have the answer.

Where you use : on an App Service, use a __ (double underscore) on an App Service with containers.

So Parent__ChildOne instead of Parent:ChildOne.

To read a little more (not much more), I wrote this up as a blog post here: https://blog.johnnyreilly.com/2018/07/28/azure-app-service-web-app-containers-asp-net-nested-configuration/

这篇关于在用于容器的 Azure Web App 上使用 ASP.Net Core 配置 AppSettings:冒号在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆