Amir Krish

Amir Krish

  • NA
  • 5
  • 1.3k

Custom Section / NameValueSectionHandler in Webconfig

Mar 15 2016 3:17 AM
 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
  1. <sectionGroup name="Menu">  
  2. <section name="Links" type="System.Configuration.NameValueSectionHandler"/>  
  3. </sectionGroup>  
C#
  1. NameValueCollection nameValueCol = (NameValueCollection)ConfigurationManager.GetSection("Menu/Links");  
  2. var Key = "Key";  
  3. var Value = "Value";  
  4. nameValueCol.Set(Key, Value); // Error: collection is read only  
so I tried to remove and add the keys still it shows same error.
  1. nameValueCol.Remove(Key); // Error: collection is read only  
  2. nameValueCol.Add(Key, Value); 

Answers (3)