Created
          April 12, 2012 20:22 
        
      - 
      
- 
        Save rroman81/ddf18093adbb6111c7c6 to your computer and use it in GitHub Desktop. 
    Code to modify the web.config in SP system
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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(); | |
| }); | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
This is included in the WebApplication scoped FeatureReceiver under FeatureInstalled event handler.