相关疑难解决方法(0)

在web.config中存储值 - appSettings或configSection - 哪个更有效?

我正在编写一个可以使用几个不同主题的页面,我将在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>
Run Code Online (Sandbox Code Playgroud)

要访问configSection中的值,我使用以下代码:

    NameValueCollection themes = ConfigurationManager.GetSection("SchedulerPage/Themes") as NameValueCollection;
    String SchedulerTheme = themes["UB"];
Run Code Online (Sandbox Code Playgroud)

appSettings解决方案

<appSettings>
    <add key="PITheme" value="PISchedulerForm"/>
    <add key="UBTheme" value="UBSchedulerForm"/>
</appSettings>
Run Code Online (Sandbox Code Playgroud)

要在appSettings中访问值,我正在使用此代码

    String SchedulerTheme = ConfigurationManager.AppSettings["UBSchedulerForm"].ToString();
Run Code Online (Sandbox Code Playgroud)

asp.net performance web-config appsettings configsection

11
推荐指数
3
解决办法
2万
查看次数

Web.config appSettings:复杂的值

Web.config的appSettings部分是否只能存储这样的简单字符串?

   <appSettings>
     <add key="OKPage" value="http://mysite.com/okpage.html" />
   </appSettings>
Run Code Online (Sandbox Code Playgroud)

或者我可以有更复杂的值,如CDATA或嵌套值?如果没有,这是否是Web.config中存储自定义设置的唯一位置?谢谢

.net c# asp.net configuration asp.net-4.0

5
推荐指数
2
解决办法
1万
查看次数