0

I am developing an application which will give a website administrator the ability to enable/disable a HttpModule without having to actually open and edit the web.config file. I have found it is quite easy to do this with appSettings node using the System.Configuration namespace, but it does not seem to include a way to modify the system.web/httpModules node.

Short of simply using XDocument/XElement, does anyone know of another way to do this? I have seen a couple of other ways involving some of the app start or app pre-start events, but I'm not sure this is a viable solution for me, since this is a HttpModule for a website that is already running. I have found the System.Web.Configuration.HttpModulesSection class, but this seems to be read-only. Any assistance would be much appreciated.

tjc59
  • 633
  • 8
  • 24

1 Answers1

0

The modules list is immutable once pre-app start has completed. That the list is immutable is required by IIS, so it's not something we can ever change in the ASP.NET layer.

Your best course of action would be to have the module always registered, but make its methods no-op if it has been "disabled". You might find it easier to wrap the original IHttpModule inside a helper wrapper IHttpModule to accomplish this.

Levi
  • 32,628
  • 3
  • 87
  • 88