Tuesday, March 11, 2008 7:00 AM Jan Tielens

SPWebConfigModification Best Practices and Guidelines

The SPWebConfigModification class allows developers to write code that will make modifications to the web.config files of SharePoint sites. This is quite often necessary when you want to deply SharePoint customizations together with configuration settings. Using the SPWebModification class is not without any danger! :-) You can mess up your web.config files especially if you don't think about how you want to be able to undo your changes. Mark Wagner wrote an excellent article about the best practices related to the SPWebConfigModification class; required reading for every SharePoint developer. Mark explains some very important things you should know to get started:

  • To save the modifications, you must use of the following code:
    myWebApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
    myWebApp.Update();
  • Only call this code once in your feature handler, otherwise you get the error "A web configuration modification operation is already running."

Great info Mark, and please do create an complete example of the best practices, packaged in a feature!

Filed under:

Comments

# re: SPWebConfigModification Best Practices and Guidelines

Tuesday, March 11, 2008 6:49 AM by Aaron Powell

Hey Jan,

Do you think it would be possible to programmatically modify the web.config to add all the Microsoft AJAX extensions?

I think it would be... just it would be rather err... tedious to code ;)

# re: SPWebConfigModification Best Practices and Guidelines

Tuesday, March 11, 2008 9:17 AM by Becky Isserman

If you are writing a feature or a web part wouldn't it be a better idea to use VSEWSS1.1 or STSDEV, so that you never have to touch this class at all?  It just sounds like one of those scary things you could mess up, so why touch if you really don't need to with all the great tools out there?

# re: SPWebConfigModification Best Practices and Guidelines

Wednesday, March 12, 2008 6:57 AM by Jan Tielens

@Aaron, yes it is possible and yes it would require some boring code. :-) But I'd rather write that code once, instead of having to change the web.config hundreds of times!

@Becky, I don't see how VSEWSS or STSDEV would help in the scenarios where you would like to use SPWebConfigModification. You don't make use of this SPWebConfigModification when you want to add a SafeControl entry of course, the WSP deployment has to do this.

# SharePoint 2007 Link Love: 03-12-2008 at Virtual Generations

Pingback from  SharePoint 2007 Link Love: 03-12-2008 at  Virtual Generations

# re: SPWebConfigModification Best Practices and Guidelines

Wednesday, March 12, 2008 5:48 PM by Aaron Powell

@Jan - Well if you were to write the boring code I'm sure us in the community would be more than appreciative of it ;)

# re: SPWebConfigModification Best Practices and Guidelines

Tuesday, May 13, 2008 5:30 AM by Ajay

Hi Jan,

I have a sharepoint application for which I had to change the session state to be in-proc than the default SqlServer.

I have noticed that if I reboot the server or do some changes to that application, session state changes to SqlServer in the web.config and site breaks... I have to then open web.config and change it back to in-proc.

Can you think of why this kind of thing happens.. it does not change anything else in the web.config only session attribute changes.

Someone suggested to use SPWebConfigModification,,  what do you think.

Thanks

Ajay

# funny wallpaper &raquo; SPWebConfigModification Best Practices and Guidelines

Pingback from  funny wallpaper &raquo; SPWebConfigModification Best Practices and Guidelines