我使用下面的代码来读取配置。此代码用于全局。asax Application_Start方法。
var showAllMethodSetting = ConfigurationManager.AppSettings["ShowAllMethodsInSwaggerDocs"]; bool showAllMethods; if (!bool.TryParse(showAllMethodSetting, out showAllMethods) || !showAllMethods) { ... code ... }
它在我的本地配置(appSetting.config)中运行良好,但当我将代码推送到Azure时。它不起作用。
条目ShowAllMethodsInSwagerDocs在Azure面板中可见,具有正确的值(我在*.csdef和*.cscfg中添加了节点),但未使用该值。为什么?也许我应该使用ConfigurationManager以外的其他类吗?
你需要使用nuget包 Microsoft Azure Configuration Manager 在门户和web.config中获取配置设置。