I have custom section Links which I Should edit from UI. While saving I couldn't save the value of the corresponding key. It shows "collection is read only" error. Please help me to resolve this. Thanks in Advance.
WebConfig
- <sectionGroup name="Menu">
- <section name="Links" type="System.Configuration.NameValueSectionHandler"/>
- sectionGroup>
C#
- NameValueCollection nameValueCol = (NameValueCollection)ConfigurationManager.GetSection("Menu/Links");
- var Key = "Key";
- var Value = "Value";
- nameValueCol.Set(Key, Value); // Error: collection is read only
so I tried to remove and add the keys still it shows same error.
- nameValueCol.Remove(Key); // Error: collection is read only
- nameValueCol.Add(Key, Value);
Rajeev PunhaniPosted Mar 15, 2016, 4:49 AM
Hi Amir,
Please find the below link.
Rajeev PunhaniPosted Mar 15, 2016, 7:41 AM
Hi Amir,
you can edit those values but those won't be reflected in web.config if you open it until application is restarted.If application is restarted you sessions will be lost.
If the above solution is helpful then,accept the answer.
Amir KrishPosted Mar 15, 2016, 7:00 AM