Static property modification

Joined
Jan 30, 2009
Messages
1
Reaction score
0
Hello everyone.

I have an asp.net app and was trying to simplify access to a Web Configuration object so I wrapped it into a static property. Everything is fine, but when I try to modify AppSettings key it just doesn't work!

public class Test
{
public static Configuration Config
{
get
{
return WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
}
}


public static void SaveAppSettings()
{
Config.AppSettings.Settings.Add("direct", "DIRECT");
Config.Save(ConfigurationSaveMode.Modified);

Configuration cfg = Config;
cfg.AppSettings.Settings.Add("bypass", "BYPASS");
cfg.Save(ConfigurationSaveMode.Modified);
}

}


Pre-conditions: both "direct" and "bypass" keys do exist in app settings in web.config. Execution results in "bypass" property being rewritten in web.config. And "direct" is not. In debug i can see that line
Config.AppSettings.Settings.Add("direct", "DIRECT");
does not actually modify a property, and line
cfg.AppSettings.Settings.Add("bypass", "BYPASS");
does. Why?
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,102
Messages
2,570,645
Members
47,245
Latest member
ShannonEat

Latest Threads

Top