【问题标题】:ConfigurationManager on Azure environmentAzure 环境中的 ConfigurationManager
【发布时间】:2016-01-25 09:59:30
【问题描述】:

我使用下面的代码来读取配置。此代码用于 global.asax Application_Start 方法中。

        var showAllMethodSetting = ConfigurationManager.AppSettings["ShowAllMethodsInSwaggerDocs"];
        bool showAllMethods;
        if (!bool.TryParse(showAllMethodSetting, out showAllMethods) || !showAllMethods)
        {
            ... code ...
        }

它在我的本地配置 (appSetting.config) 中运行良好,但是当我将代码推送到 Azure 时。它不起作用。

Entry ShowAllMethodsInSwaggerDocs 在 Azure 面板中可见,具有适当的值(我在 *.csdef 和 *.cscfg 中添加了节点),但未使用此值。为什么?也许我应该使用 ConfigurationManager 以外的其他类?

【问题讨论】:

  • 您是否在应用部署后添加了门户设置,并且应用设置和门户设置使用相同的名称?
  • 你可能想考虑一个抽象这个的库 - github.com/aloneguid/config

标签: c# .net azure asp.net-web-api configuration


【解决方案1】:

您需要使用 nuget 包 Microsoft Azure Configuration Manager 来获取门户和 web.config 中的配置设置。

【讨论】:

  • @Jacek 是的,绝对应该!它本质上是一个包,将从 azure 配置中读取,然后回退到通常的 *.config 文件
猜你喜欢
  • 1970-01-01
  • 2014-10-21
  • 2021-12-23
  • 1970-01-01
  • 2011-06-11
  • 2021-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多