Tuesday, March 22, 2011

2010 SPWebConfigModifications Applied

I have been noticing a few issues about SPWebConfigModifications and how they are applied.

Service Level SPWebConfigModification Applied

For instance if you have two web applications on your content service one on port 80 and other on port 8080. You can choose to have your web config modifications added to all of web applications by adding them at the SPWebService level.

SPWebService.ContentService.WebConfigModificaitons.Add(myWebConfigModification);
SPWebService.ContentService.Update();
SPWebService.ContentService.ApplyWebConfigModifications();

Advantages:
  • Applied to all web applications at once
  • Applied to new web applications when created
  • Can be used in an auto activated farm SPFeatureDefinition
Disadvantages
  • Will be applied to web applications set up by third party applications that may have special purposes which may damage these applications
  • The actual SPWebModificaitons may reference specific solution based software that may not be deployed globally
Web Application Level SPWebConfigModificaitons

Alternatively it is possible to apply SPWebConfigModificaiton to a specific SPWebApplicaiton.

SPWebApplication myWebApplication;
:
myWebApplication.WebConfigModifications.Add(myWebConfigModification);
myWebApplication.Update();
SPWebService.ContentService.ApplyWebConfigModifications();

Advantages:
  • Scopes to the WebApplication level SPFeatureDefinition
  • Can be added to a WebApplication deployed SPSolution
  • Can be added to a WebApplicaition feature that may be auto activated/deactivated
Disadvantages:
  • Auto activate features always activate on create new web application.  You must make sure all necessary infrastructure pieces are in place to support the new web application as it bootstraps into IIS.
Summary:

In general the create new web application use case is often the most overlooked use case by developers.  SPWebService level SPWebConfigModificaitons will be applied to this use case.  Additionally WebApplication auto activate features will be applied to this use case.  As you program SPWebConfigModificaitons, make sure you do not block the farm administrator from creating new web applications.