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.
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.
I'm afraid I no longer use this forum due to the new point allocation system.
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
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
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
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
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?
Member
130 Points
229 Posts
Writable Configuration
Dec 12, 2013 01:02 PM|IranianCuriousBoy|LINK
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
All-Star
37441 Points
9076 Posts
Re: Writable Configuration
Dec 12, 2013 01:06 PM|AidyF|LINK
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.
Member
130 Points
229 Posts
Re: Writable Configuration
Dec 13, 2013 01:36 AM|IranianCuriousBoy|LINK
Hi
Why is there setters in the sample code?
All-Star
32817 Points
3815 Posts
Re: Writable Configuration
Dec 26, 2013 10:08 PM|Angie xu - MSFT|LINK
HI
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
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
130 Points
229 Posts
Re: Writable Configuration
Dec 28, 2013 05:37 AM|IranianCuriousBoy|LINK
Hi Angie
You mean when I use GetSection() overloaded methods, the access will be read-only after that?
Regards
All-Star
32817 Points
3815 Posts
Re: Writable Configuration
Dec 30, 2013 02:29 AM|Angie xu - MSFT|LINK
Hi,
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
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
130 Points
229 Posts
Re: Writable Configuration
Jan 16, 2014 05:37 AM|IranianCuriousBoy|LINK
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