Azure 环境中的 ConfigurationManager

ConfigurationManager on Azure environment

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

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

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

条目 ShowAllMethodsInSwaggerDocs 在 Azure 面板中可见,并具有正确的值(我在 *.csdef 和 *.cscfg 中添加节点),但未使用此值。为什么?也许我应该使用其他 class 而不是 ConfigurationManager?

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