Programatically add (and remove) an HttpModule to SharePoint Web.config
Sometimes you need to use an HttpHandler or HttpModule in a SharePoint application - I am using one to handle the requests to the system pages and to replace the application.master on them with my own master. To install this module I need to register the dll in the GAC and to add a HttpModule declaration in the web.config.
To modify the web.config programatically in SharePoint you can use the SPWebConfigModification class. There are many examples on the net about using this class, and the one I started with is this one. Unfortunately, this example, along with all the others on the subject are healing with adding HttpHandler elements, while I needed to play with an HttpModule element. The example does apply to me for adding an element, but the issue arises when I need to remove it.
The SPWebConfigModification class has a Name property. This property should be set to the relative XPath to the modification and maps to the Path attribute of an HttpHandler element. The property is used to locate the element when you need to remove it. Unfortunately, the HttpModule element does not have the Path attribute. So no matter how I tried it, I could not remove the element from the web.config.
The solution came while I was reading a different post about web.config inheritance: the tag. If you want to remove the HttpModule element, add a tag to the web.config.








Recent Comments
Starting form the sample I mentioned
Thanks for posting this. It sav
The left image does not overlap t
Was Looking for the "inline" and "at