Asked by:
Writable Configuration

Question
-
User539648229 posted
Hi
I read "How to: Create Custom Configuration Sections Using ConfigurationSection" at http://msdn.microsoft.com/en-us/library/2tw134k3(v=vs.90).aspx and created required code that reads configuration sections successfully but when I assign a value to the configuration sections(properties that have setter), there is an error that says "The configuration is read only". How can I write to these properties and save to web.config.
Thanks
Thursday, December 12, 2013 1:02 PM
All replies
-
User-760709272 posted
You can read the web.cong file as xml using XmlDocument, change it then save it, however note that if you do this your site will recycle. If you want a writable configuration that won't reboot your application then just maintain a standard xml file somewhere in the App_Data folder (bearing mind multi-threading issues) rather than messing about with the config class. Configuration is intended to be read-only.
Thursday, December 12, 2013 1:06 PM -
User539648229 posted
Hi
Why is there setters in the sample code?
Friday, December 13, 2013 1:36 AM -
User-166373564 posted
HI
but when I assign a value to the configuration sections(properties that have setter), there is an error that says "The configuration is read only".The Configuration class allows programmatic access for editing configuration files. You can access these files for reading or writing as follows:
-
Reading. You use GetSection or GetSectionGroup to read configuration information. Note that the user or process that reads must have the following permissions:
-
Read permission on the configuration file at the current configuration hierarchy level.
-
Read permissions on all the parent configuration files.
-
If you use the GetSection() overloaded methods in the case of Web applications, or the ConfigurationManager.GetSection method in the case of client applications. your application will be read-only access to its own configuration.
hope it helps,
Regards
Thursday, December 26, 2013 10:08 PM -
-
User539648229 posted
Hi Angie
You mean when I use GetSection() overloaded methods, the access will be read-only after that?
Regards
Saturday, December 28, 2013 5:37 AM -
User-166373564 posted
Hi,
You mean when I use GetSection() overloaded methods, the access will be read-only after that?Yes. As I mentioned above, please check whether it has this issue.
If it still has same issue, please don’t hesitate to let me know.
Best regards
Angie
Monday, December 30, 2013 2:29 AM -
User539648229 posted
Hi Angie
At first I should tell that I used a separete XML for my settings. I continue this post because I'm curious about the subject and I want to learn. You confirmed that using GetSection turns the access to read-only. Is there another way to access these data that does not change permission? I think it is contradicting in nature. I have some setters and immidiately after I access the section it will turn to read-only. What these setters is for?
Thanks
Thursday, January 16, 2014 5:37 AM