开发者

Add items to Properties.Settings at runtime in an ASP.NET application

I want to add an item at runtime to my global settings on an ASP.Net web application. It seems that the Properties.Settings.Default.Properties object is read-only, or at least it's Attributes are so I was trying to write directly into the web.config file. This works correctly but the stuff I found was just dropping my info into the AppSettings section, when I need it to be in the ApplicationName.Properties.Settings so it is made available through the Default.Properties object.

The code I have basically goes like this:

   Configuration config = WebConfigurationManager.OpenWebConfiguration("/");
   config.AppSettings.Add(mySettingName, myValue);
   config.Save();

Which is fine and dandy, except that - obviously enough - my setting turns up in the <appSettings> section of the file.开发者_如何学运维

Is there a way I can use the Configuration object to access the ApplicationSettings/ApplicationName.Properties.Settings part of the configuration file? If so how? If not is there another way to write values into my application settings from code?


You can use the ConfigurationManager.GetSection() method to retrieve any section from a configuration file. However, there is no support for updating within the framework.

Read more here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜