Sep 04, 2015 03:31 PM|rstrahl|LINK
The code you referenced is from my blog a long time ago and that works only to *add* a module dynaimcally at runtime. You can't use it to remove modules or other content from Web.config. What you are trying to do is essentially override a setting.
The easiest and most consistent (but hacky) way to do this is to just an XML parser to load the web.config as an XML document, update it and write back out. There are APIs that allow writing settings but they require special components that may not be present
and full admin rights so in many cases it's just easier to load the document up and modify it directly.
You can use Linq to XML to make this pretty painless or XmlDocument if you want a more traditional approach.
Note that you will need to make sure that your application pool has WRITE access to the web.config file in order for this to work.
+++ Rick ---