简体   繁体   中英

How to set list of values in IIS web.config?

In IIS web config custom settings (appSettings), I have this

<add key="vals" value="one,two,three" />

but is there a way to change it to

<add key="vals">
    <value>one</value>
    <value>two</value>
    <value>three</value>
</add>

?

To answer your question, I am sure you CANNOT do this with the default AppSettings section.

I would suggest to use either comma seprated or semi-colon separated values in such cases.

If you really want the XML structure you have shown, then you can also go for custom configuration sections. If you want example is here .

You could make list like below in web.config file:

<appSettings>
    <add key ="users" value="usera,userb"/>
  </appSettings>

you can access like:

  string[]  usersValues = System.Configuration.ConfigurationManager.AppSettings["users"].Split(",");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM