❔ Adding managed module to Web.config programmatically in ASP.NET
Hi everyone! I have a kind-of niche situation in which I am required to programmatically add a managed module (when running under IIS 10.0) to an ASP.NET MVC 4 application. The good news is that we actually want the app to restart, so dynamic loading is not required. Instead, I need to add the module to the application's Web.config file, under configuration/system.webServer/modules. I have tried to implement this in several ways, including opening the config file using Microsoft.Web.Administration, plain old System.Configuration or the ServerManager path. All of these resulted in failure since either the configuration is read-only or not found at all in the case with ServerManager.
As a last resort, I used an XmlDocument instance and manually created the needed nodes myself, after which I restart the application manually. However, this seems like the wrong approach to me. Having to open the app's config file as an xml document and edit it seems very "wooden" to me and I suspect it might lead to more problems along the path. Does anyone have any insight on the issue? Something I could have done better? Of course, I can provide code examples of the other methods I tried.
Thank you 🙂
1 Reply
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.