我想创建一个将由exe(app.config)或网站(web.config)使用的库。如果我创建自定义配置部分,并使用
加载它Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
CustomSection section = config.Sections.OfType<CustomSection>().FirstOrDefault();
它不会在网站上运行。它会引发exePath must be specified when not running inside a stand alone exe.
异常,因为它不是exe。我可以使用类似的东西:
CustomSection db = (CustomSection )ConfigurationSettings.GetConfig("CustomSection");
但这依赖于正确命名的部分。有没有办法获得所有部分并迭代它们?