Welcome to Atalasoft Community Sign in | Join | Help

Using SPWebConfigModification, Part 1 - The Problem

 

The Problem

 

I've read a lot of posts [this, this, and this, for example] about the SPWebConfigModification beast and I've had a lot of time developing a SharePoint MOSS/WSS feature that utilizes this part of the SharePoint Object Model.

Generally, I see a lot of confusion around the internet about when to use the type EnsureSection vs. EnsureChildNode and the consensus I've seen is to always use EnsureChildNode because it allows you to later delete the section when your feature or site is deleted; I disagree, only partly.

One must realize that SharePoint is a big beast and has a lot of pieces.  If you're going to distribute a feature that requires web.config modifications, then you're going to need to ensure that certain sections exist before putting down the child nodes.  Go ahead and try to add an appSetting key when the <appSettings> section doesn't exist (as it doesn’t in default WSS installs), it won't work!  SharePoint will give a backwards error about not finding the web.config node in the [node] file, like this:

"Failed to apply a web.config modification to file 'configuration/appSettings'.  The specified node "C:\Inetpub\wwwroot\wss\VirtualDirectories\80\web.config" was not found in the web.config file."

But as we all know this means it couldn't find the node in the web.config file.

If you debug on MOSS and have a look at the SPWebConfigModification[s] collection inside a web, you might see the httpModules section and the subsequent EnsureChildNode entry for the session state handler.  This is a great example of how things should be done, or at least how I think Microsoft thinks it should be done.

Let me quickly mention that there also seems to be some confusion about where to call ApplyWebConfigModifications.  The SharePoint SDK documentation states:

To apply modifications that you define through the SPWebConfigModification class to the web.config files in the server farm, call the ApplyWebConfigModifications method on the current content Web service object, as follows: SPWebService.ContentService.ApplyWebConfigModifications.

So, call it from the content service of the web service!

Now, how about a good example...

   
Published Wednesday, October 08, 2008 1:06 PM by dterrell

Comments

Wednesday, October 08, 2008 1:12 PM by If you build it, They will come

# Using SPWebConfigModification, Part 2

We're in Part 2 of a 5 part blog post about the SPWebConfigModification object and my trials with it.

Wednesday, October 08, 2008 1:17 PM by If you build it, They will come

# Using SPWebConfigModification, Part 3

We're in Part 3 of a 6 part blog post about the SPWebConfigModification object and my trials with it.

Wednesday, October 08, 2008 1:19 PM by If you build it, They will come

# Using SPWebConfigModification, Part 4

We're in Part 3 of a 6 part blog post about the SPWebConfigModification object and my trials with it.

Wednesday, October 08, 2008 1:21 PM by If you build it, They will come

# Using SPWebConfigModification, Part 5

We're in Part 3 of a 6 part blog post about the SPWebConfigModification object and my trials with it.

Wednesday, October 08, 2008 1:23 PM by If you build it, They will come

# Using SPWebConfigModification, Part 6

We're in Part 3 of a 6 part blog post about the SPWebConfigModification object and my trials with it.

Wednesday, October 15, 2008 3:30 PM by DotNetKicks.com

# Using SPWebConfigModification, Part 1 - The Problem

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Thursday, December 11, 2008 7:54 AM by Jake Opines

# Your SharePoint web.config and You

This post talks about the dos-and-don'ts of manipulating your web.config and explains some of the future

Monday, January 12, 2009 10:35 AM by Jake Opines

# SharePoint Saturday: Developing and Packaging a Third Party SharePoint Solution

Here are some notes from my presentation at SharePoint Saturday this past weekend in Virginia Beach,

Anonymous comments are disabled