Add a setting in Web. config.
1. Construct a section between <configsections> </configsections>, as shown in figure
<Configsections>
<Section name = "mysection" type = "system. configuration. namevaluesectionhandler, system"/>
</Configsections>
You can also set a section group and the group can be nested.
<Configsections>
<Sectiongroup name = "mygroup">
<Sectiongroup name = "nestedgroup">
<Section name = "mysection" type = "system. configuration. namevaluesectionhandler, system"/>
</Sectiongroup>
</Sectiongroup>
</Configsections>
2. Add the sections settings between <configuration> </configuration> and the <configsections> </configsections> level.
<Mysection>
<Add key = "key_one" value = "1"/>
<Add key = "key_two" value = "2"/>
</Mysection>
Or use the section group method.
<Mygroup>
<Nestedgroup>
<Mysection>
<Add key = "key_one" value = "1"/>
<Add key = "key_two" value = "2"/>
</Mysection>
</Nestedgroup>
</Mygroup>
3. Read Value
Dim config as namevaluecollection = configurationsettings. getconfig ("mysection ")
Or
Dim config as namevaluecollection = configurationsettings. getconfig ("mygroup/nestedgroup/mysection ")
The above method is used when the configuration type to be added is complicated. For example, the above type is a class. Each of the preceding keys is an attribute in the class.
If the configuration to be added is only a text string, you can directly use the <deleetting> Configuration section
<Deleetask>
<Add key = "AAA" value = "BBB"/>
</Deleetting>
Directly use
Dim X as string = configurationsettings. deleettings ("AAA ")
You can.
<Location> </location> Configuration section usage
<Location> </location> is used to apply a set of configurations to a specific application directory.
For example,
<System. Web>
<Compilation defaultlanguage = "VB"/>
</System. Web>
<Location Path = "C # code">
<System. Web>
<Compilation defaultlanguage = "CS"/>
</System. Web>
</Location>
Only in the C # code directory, the default language is C #, and other directories are VB