Click to See Complete Forum and Search --> : web.config custom sections.


ireland
October 16th, 2006, 11:05 AM
I thought I'd use the Custom Sections in a web.config to store some strings.
I wish to use the web.config to enable the client's admin to edit messages which may appear in the application.
I want development to have the ability to add strings which will be keyed using a string name and accessed from our code base using only the string name as a parameter.
I've tried these custom sections and followed the example at msdn, http://msdn2.microsoft.com/en-us/library/ms228056.aspx, but I don't really see the use of this now because from what I can see if the a developer wishes to add a string to the web.config then they'll be required to edit the handler too, this is no use!
I want the handler to return the string which is keyed using a string, the key passed in is the string name.

Here is the type of format of the config file that I was hoping to use:

<!-- Configuration section settings area. -->
<myCustomGroup>
<myCustomSection Message="Message">
<myChildSection
messagestring1="I'm the first string edit me."
messagestring2="I'm the second string edit me."
messagestring3="I'm the third string edit me."
.......

/>
</myCustomSection>
</myCustomGroup>


I hoped development could simply add a new attribute and value to the myChildSection element and then access it from code using the attribute as a parameter to an accessor function!

mmetzger
October 18th, 2006, 04:34 PM
I think the whole reason for this is strong typing. The idea is to properly parse any information and make sure the code reacts as you'd expect.

That said, though the use is somewhat deprecated, you can always use the appSettings.


web.config

<configuration>
<appSettings>
<add key="myString1" value="myValue" />
<add key="myString2" value="myValue2" />
</appSettings>
</configuration>

In code

string myString1 = System.Configuration.ConfigurationSettings.AppSettings["myString1"];
string myString2 = System.Configuration.ConfigurationSettings.AppSettings["myString2"];

ireland
October 19th, 2006, 04:20 AM
Cheers mmetzger,
I'm aware of the appsettings but I don't want to add to it. I'd prefer to have a seperate section dedicated to messages.
I found a solution, it uses Custom Configuration Handlers.
http://forums.asp.net/thread/1097885.aspx