【发布时间】:2012-12-13 18:58:08
【问题描述】:
我有一个类需要从应用程序配置文件中获取一些设置,并且用于基于控制台的应用程序和 Web 应用程序。
除了捕获异常我如何确定是否使用:
ServiceModelSectionGroup serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));
或
ServiceModelSectionGroup serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(WebConfigurationManager.OpenWebConfiguration("~"));
【问题讨论】:
-
也许我遗漏了什么——你为什么不能使用
ConfigurationManager.GetSection()? -
我需要在 system.serviceModel 配置节点中列出客户端端点,我认为 GetSection 方法不允许我将该节点作为 ServiceModelSectionGroup 对象检索。
-
您可以将其作为
SectionGroup和cast 到ServiceModelSectionGroup。 -
@Oded ConfigurationManager.GetSection("system.serviceModel") 返回 null。
标签: .net web-config app-config