Skip to content

Instantly share code, notes, and snippets.

@rroman81
Created April 12, 2012 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rroman81/ddf18093adbb6111c7c6 to your computer and use it in GitHub Desktop.
Save rroman81/ddf18093adbb6111c7c6 to your computer and use it in GitHub Desktop.
Code to modify the web.config in SP system
var modifications = new List<SPWebConfigModification>()
{
new SPWebConfigModification("remove[@name='BotDetectCaptachHandler'",
"configuration/system.webServer/handlers")
{
Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode,
Value = @"<remove name='BotDetectCaptchaHandler'/>"
},
new SPWebConfigModification("add[@name='BotDetectCaptchaHandler'",
"configuration/system.webServer/handlers")
{
Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode,
Value = @"<add name='BotDetectCaptchaHandler' preCondition='integratedMode' verb='GET' path='BotDetectCaptcha.ashx' type='BotDetect.Web.CaptchaHandler, BotDetect' />"
}
};
SPSecurity.RunWithElevatedPrivileges( () =>
{
var contentService = SPWebService.ContentService;
foreach (var modification in modifications)
{
contentService.WebConfigModifications.Add(modification);
}
contentService.Update();
contentService.ApplyWebConfigModifications();
});
@rroman81
Copy link
Author

This is included in the WebApplication scoped FeatureReceiver under FeatureInstalled event handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment