Question

I have custom web.config functionality that uses Linq to merge elements into a web.config based on a template file. I would like to use this in a feature so I can get it to merge all web.configs in a load balancing environment. I know there is something called SPWebConfigModification, but the extent of the elements to add is large and I need it to be more dynamic like the template solution. I know I could run it on each front end server, but it would be better in a feature or solution.

Is there a way to get access to the web.config in a feature in SharePoint 2007?

Was it helpful?

Solution

If you're really sure you don't want to use SPWebConfigModification, you could look at SPWebService.ApplyApplicationContentToLocalServer() - this has the capability of merging entire sections into config files, but has the following caveats:

  • Only applies to the local server (clue is in the name!)
  • Must be called by a local administrator

The combination of these two caveats means you can't use the normal pattern of using a timer job to ensure something executes on all servers in a farm. If you were happy to write say, a windows service which would call this web service, well that would get you round it.

However my recommendation would be to stick with SPWebConfigModifcation. Regardless of how big a custom section is, it's going into the web.config as a child node of a node somewhere so can be added as an 'EnsureChildNode'. It would certainly be possible to combine your merge functionality with SPWebConfigModification (i.e. pass in the merged XML to calls to SPWebConfigModification), and then you can be sure the change will applied across the whole farm. Also, it's easy to write code to remove the changes (e.g. in the Feature Deactivated event if your host code is a Feature receiver).

OTHER TIPS

Don't you have source code of the merger application ? I guess you may be able to use sharepoint api to access the web.conf file, including your code in a feature.

sounds interesting at least,

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top