我正在编写一个可以使用几个不同主题的页面,并且我将在 web.config 中存储有关每个主题的一些信息。
创建一个新的sectionGroup并将所有内容存储在一起,还是将所有内容放在appSettings中更有效?
configSection解决方案
<configSections>
<sectionGroup name="SchedulerPage">
<section name="Providers" type="System.Configuration.NameValueSectionHandler"/>
<section name="Themes" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<SchedulerPage>
<Themes>
<add key="PI" value="PISchedulerForm"/>
<add key="UB" value="UBSchedulerForm"/>
</Themes>
</SchedulerPage>
要访问 configSection 中的值,我使用以下代码:
NameValueCollection themes = ConfigurationManager.GetSection("SchedulerPage/Themes") as NameValueCollection;
String SchedulerTheme = themes["UB"];
appSettings 解决方案
<appSettings>
<add key="PITheme" value="PISchedulerForm"/>
<add key="UBTheme" value="UBSchedulerForm"/>
</appSettings>
要访问 appSettings 中的值,我正在使用此代码
String SchedulerTheme = ConfigurationManager.AppSettings["UBSchedulerForm"].ToString();